using AutoMapper; using Imprink.Application.Exceptions; using Imprink.Application.Users.Dtos; using MediatR; namespace Imprink.Application.Users.Commands; public record GetUserRolesCommand(string Sub) : IRequest>; public class GetUserRolesHandler(IUnitOfWork uw, IMapper mapper): IRequestHandler> { public async Task> 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>(roles); } }