Files
FrontOffice.BFF/src/FrontOffice.BFF.Application/UserCQ/Queries/GetUser/GetUserQueryHandler.cs

23 lines
901 B
C#
Raw Normal View History

namespace FrontOffice.BFF.Application.UserCQ.Queries.GetUser;
public class GetUserQueryHandler : IRequestHandler<GetUserQuery, GetUserResponseDto>
{
private readonly IApplicationContractContext _context;
private readonly ICurrentUserService _currentUserService;
public GetUserQueryHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
{
_context = context;
_currentUserService = currentUserService;
}
public async Task<GetUserResponseDto> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
var userId = _currentUserService.UserId ?? throw new ForbiddenAccessException();
var response = await _context.User.GetUserAsync(request: new()
{
Id = long.Parse(userId)
}, cancellationToken: cancellationToken);
return response.Adapt<GetUserResponseDto>();
}
}