#27 added userTransactions

This commit is contained in:
Dominic Villemure
2024-04-22 15:55:49 -04:00
parent cbde9838d1
commit b63d53f109
17 changed files with 696 additions and 28 deletions

View File

@@ -0,0 +1,37 @@
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.Id == currentUserId)
.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;
}
}

View File

@@ -0,0 +1,12 @@
namespace Hutopy.Application.Users.Queries;
public class UserDto
{
public Guid Id { get; init; }
public required string FirstName { get; init; }
public required string LastName { get; init; }
public List<UserTransactionDto> UserTransactions { get; init; } = [];
}

View File

@@ -0,0 +1,20 @@
using Hutopy.Domain.Entities;
namespace Hutopy.Application.Users.Queries;
public class UserTransactionDto
{
public required decimal Amount { get; init; }
public string Currency { get; init; } = "cad";
public string TipMessage { get; init; } = string.Empty;
private class Mapping : Profile
{
public Mapping()
{
CreateMap<UserTransaction, UserTransactionDto>();
}
}
}