everybody loves a refactor

This commit is contained in:
2026-02-15 12:27:36 +11:00
parent 27915d0047
commit 51cb987269
44 changed files with 278 additions and 234 deletions

View File

@@ -30,7 +30,7 @@ func (r Role) isSystem() bool {
}
// GetRoleByName queries the database for a role matching the given name
// Returns nil, nil if no role is found
// Returns a BadRequestNotFound error if no role is found
func GetRoleByName(ctx context.Context, tx bun.Tx, name roles.Role) (*Role, error) {
if name == "" {
return nil, errors.New("name cannot be empty")
@@ -39,7 +39,7 @@ func GetRoleByName(ctx context.Context, tx bun.Tx, name roles.Role) (*Role, erro
}
// GetRoleByID queries the database for a role matching the given ID
// Returns nil, nil if no role is found
// Returns a BadRequestNotFound error if no role is found
func GetRoleByID(ctx context.Context, tx bun.Tx, id int) (*Role, error) {
return GetByID[Role](tx, id).Relation("Permissions").Get(ctx)
}
@@ -110,9 +110,6 @@ func DeleteRole(ctx context.Context, tx bun.Tx, id int, audit *AuditMeta) error
if err != nil {
return errors.Wrap(err, "GetRoleByID")
}
if role == nil {
return errors.New("role not found")
}
if role.IsSystem {
return errors.New("cannot delete system roles")
}