#27 get last receipt, get minimalUser, get my user
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Domain.Interfaces;
|
||||
|
||||
namespace Hutopy.Application.Users.Queries;
|
||||
|
||||
public record GetCurrentUserQuery : IRequest<UserDto>;
|
||||
|
||||
public class GetCurrentUserQueryHandler(
|
||||
IApplicationDbContext context,
|
||||
IMapper mapper,
|
||||
IUserService userService
|
||||
)
|
||||
: IRequestHandler<GetCurrentUserQuery, UserDto>
|
||||
{
|
||||
public async Task<UserDto> Handle(GetCurrentUserQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var identityUser = await userService.GetCurrentUserAsync();
|
||||
var currentUserId = new Guid(identityUser?.Id ?? "");
|
||||
|
||||
var transactions = await context.UserTransactions
|
||||
.Where(x => x.ApplicationUserId == currentUserId.ToString())
|
||||
.OrderBy(x => x.LastModified)
|
||||
.ProjectTo<UserTransactionDto>(mapper.ConfigurationProvider)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
var user = new UserDto()
|
||||
{
|
||||
Id = currentUserId,
|
||||
FirstName = identityUser?.FirstName ?? "",
|
||||
LastName = identityUser?.LastName ?? "",
|
||||
UserTransactions = transactions
|
||||
};
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user