Files
RenewCMS/internal/infrastructure/useCases/roleRef.go
T

43 lines
792 B
Go

package useCases
import (
"RenewCMS/internal/domain/invite"
"RenewCMS/internal/domain/role"
)
type InviteView struct {
invite.Invite
Role RoleRef
}
type RoleRef struct {
ID uint32
Name string
BuiltIn bool
Locked bool
}
func NewRoleRef(found role.Role) RoleRef {
return RoleRef{ID: found.ID, Name: found.Name, BuiltIn: found.BuiltIn, Locked: found.Locked}
}
func roleRefsByID(roles role.Repository) (map[uint32]RoleRef, error) {
listed, err := roles.List()
if err != nil {
return nil, err
}
refs := make(map[uint32]RoleRef, len(listed))
for _, found := range listed {
refs[found.ID] = NewRoleRef(found)
}
return refs, nil
}
func lookupRoleRef(refs map[uint32]RoleRef, id uint32) *RoleRef {
ref, known := refs[id]
if !known {
return nil
}
return &ref
}