23 lines
816 B
C#
23 lines
816 B
C#
using MediatR;
|
|
using Modules.User.Application.Models.Access;
|
|
using Modules.User.Application.Repositories;
|
|
|
|
namespace Modules.User.Application.Queries.Access;
|
|
|
|
public class GetRoleQuery : IRequest<Role>
|
|
{
|
|
public int RoleId { get; init; }
|
|
}
|
|
|
|
public class GetRoleQueryHandler(IRoleQueries roleQueries) : IRequestHandler<GetRoleQuery, Role>
|
|
{
|
|
public async Task<Role> Handle(GetRoleQuery request, CancellationToken cancellationToken)
|
|
{
|
|
// var accountId = userContext.GetAccountId();
|
|
// if (!accountId.HasValue) return [];
|
|
// //TODO: if (!accountId.HasValue) throw new UnauthorizedAccessException("AccountId not found");
|
|
|
|
var role = await roleQueries.GetDetailByIdAsync(request.RoleId, cancellationToken);
|
|
return role ?? throw new Exception("Role not found");
|
|
}
|
|
} |