31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
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 = userId
|
|
}, cancellationToken: cancellationToken);
|
|
var result = response.Adapt<GetUserResponseDto>();
|
|
var getJwtToken = await _context.User.GetJwtTokenAsync(request: new()
|
|
{
|
|
Id = userId
|
|
}, cancellationToken: cancellationToken);
|
|
if(getJwtToken != null && !string.IsNullOrWhiteSpace(getJwtToken.Token))
|
|
result.Token = getJwtToken.Token;
|
|
|
|
return result;
|
|
}
|
|
}
|