package mappers import ( "RenewCMS/internal/domain/role" "RenewCMS/internal/infrastructure/persistence/models" ) func RoleToDomain(m models.Role, grants []models.RolePermission) role.Role { return role.Role{ ID: m.ID, Name: m.Name, Description: m.Description, BuiltIn: m.BuiltIn, Locked: m.Locked, Version: m.Version, Grants: GrantsToDomain(grants), } } func RoleToModel(r role.Role) models.Role { return models.Role{ ID: r.ID, Name: r.Name, Description: r.Description, BuiltIn: r.BuiltIn, Locked: r.Locked, Version: r.Version, } } func GrantsToDomain(rows []models.RolePermission) []role.Grant { grants := make([]role.Grant, 0, len(rows)) for _, row := range rows { grants = append(grants, role.Grant{Key: row.Key, Scope: role.Scope(row.Scope)}) } return grants } func GrantsToModel(roleID uint32, grants []role.Grant) []models.RolePermission { rows := make([]models.RolePermission, 0, len(grants)) for _, grant := range grants { rows = append(rows, models.RolePermission{RoleID: roleID, Key: grant.Key, Scope: string(grant.Scope)}) } return rows }