Add user and role management features
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
namespace Distribution.Features.Role;
|
||||
|
||||
public class RoleService(IRoleRepository repo)
|
||||
{
|
||||
public async Task<List<RoleResponse>> GetAllAsync() =>
|
||||
(await repo.GetAllAsync())
|
||||
.Where(r => r.IsActive)
|
||||
.Select(r => new RoleResponse(r.Id, r.Name, r.Level, r.IsActive, r.CreatedAt))
|
||||
.ToList();
|
||||
|
||||
public async Task<RoleResponse?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var role = await repo.GetByIdAsync(id);
|
||||
if (role is null || !role.IsActive) return null;
|
||||
return new RoleResponse(role.Id, role.Name, role.Level, role.IsActive, role.CreatedAt);
|
||||
}
|
||||
|
||||
public async Task<List<RolePermissionResponse>?> GetPermissionsAsync(Guid roleId)
|
||||
{
|
||||
var role = await repo.GetByIdAsync(roleId);
|
||||
if (role is null || !role.IsActive) return null;
|
||||
return (await repo.GetPermissionsAsync(roleId))
|
||||
.Select(rp => new RolePermissionResponse(rp.FK_PermissionId, rp.Permission.Code, rp.Permission.Description))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user