This commit is contained in:
lumijiez
2025-06-20 14:54:19 +03:00
parent b418607a89
commit 92bdb8444b
46 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using AutoMapper;
using Imprink.Application.Exceptions;
using Imprink.Application.Users.Dtos;
using MediatR;
namespace Imprink.Application.Domains.Users;
public record GetUserRolesCommand(string Sub) : IRequest<IEnumerable<RoleDto>>;
public class GetUserRolesHandler(IUnitOfWork uw, IMapper mapper): IRequestHandler<GetUserRolesCommand, IEnumerable<RoleDto>>
{
public async Task<IEnumerable<RoleDto>> Handle(GetUserRolesCommand request, CancellationToken cancellationToken)
{
if (!await uw.UserRepository.UserExistsAsync(request.Sub, cancellationToken))
throw new NotFoundException("User with ID: " + request.Sub + " does not exist.");
var roles = await uw.UserRoleRepository.GetUserRolesAsync(request.Sub, cancellationToken);
return mapper.Map<IEnumerable<RoleDto>>(roles);
}
}