24 lines
674 B
C#
24 lines
674 B
C#
using AutoMapper;
|
|||
|
|
using MediatR;
|
||
|
|
using mws.backend.dotnet.application.Common;
|
||
|
|
using mws.backend.dotnet.application.Users;
|
||
|
|
|
||
|
|
namespace mws.backend.dotnet.application.Auth;
|
||
|
|
|
||
|
|
public record GetProfileQuery(Guid UserId) : IRequest<UserDto>;
|
||
|
|
|
||
|
|
public class GetProfileHandler(IUnitOfWork uow, IMapper mapper)
|
||
|
|
: IRequestHandler<GetProfileQuery, UserDto>
|
||
|
|
{
|
||
|
|
public async Task<UserDto> Handle(GetProfileQuery request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var user = await uow.Users.GetByIdWithRoleAsync(request.UserId, ct);
|
||
|
|
if (user is null)
|
||
|
|
{
|
||
|
|
throw new NotFoundException("User not found");
|
||
|
|
}
|
||
|
|
|
||
|
|
return mapper.Map<UserDto>(user);
|
||
|
|
}
|
||
|
|
}
|