43 lines
856 B
Go
43 lines
856 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 `json:"id"`
|
|
Name string `json:"name"`
|
|
BuiltIn bool `json:"built_in"`
|
|
Locked bool `json:"locked"`
|
|
}
|
|
|
|
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
|
|
}
|