and another one
This commit is contained in:
@@ -2,7 +2,6 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/roles"
|
||||
@@ -43,31 +42,23 @@ func GetRoleByName(ctx context.Context, tx bun.Tx, name roles.Role) (*Role, erro
|
||||
if name == "" {
|
||||
return nil, errors.New("name cannot be empty")
|
||||
}
|
||||
return GetByField[Role](tx, "name", name).GetFirst(ctx)
|
||||
return GetByField[Role](tx, "name", name).Get(ctx)
|
||||
}
|
||||
|
||||
// GetRoleByID queries the database for a role matching the given ID
|
||||
// Returns nil, nil if no role is found
|
||||
func GetRoleByID(ctx context.Context, tx bun.Tx, id int) (*Role, error) {
|
||||
return GetByID[Role](tx, id).GetFirst(ctx)
|
||||
return GetByID[Role](tx, id).Get(ctx)
|
||||
}
|
||||
|
||||
// GetRoleWithPermissions loads a role and all its permissions
|
||||
func GetRoleWithPermissions(ctx context.Context, tx bun.Tx, id int) (*Role, error) {
|
||||
return GetByID[Role](tx, id).Relation("Permissions").GetFirst(ctx)
|
||||
return GetByID[Role](tx, id).Relation("Permissions").Get(ctx)
|
||||
}
|
||||
|
||||
// ListAllRoles returns all roles
|
||||
func ListAllRoles(ctx context.Context, tx bun.Tx) ([]*Role, error) {
|
||||
var roles []*Role
|
||||
err := tx.NewSelect().
|
||||
Model(&roles).
|
||||
Order("name ASC").
|
||||
Scan(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, errors.Wrap(err, "tx.NewSelect")
|
||||
}
|
||||
return roles, nil
|
||||
return GetList[Role](tx).GetAll(ctx)
|
||||
}
|
||||
|
||||
// CreateRole creates a new role
|
||||
|
||||
Reference in New Issue
Block a user