#27 more info to myUser and userTransactions

This commit is contained in:
Dominic Villemure
2024-05-18 00:04:10 -04:00
parent 5161e3a91a
commit 5cdfd9c639
6 changed files with 27 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
using Hutopy.Application.Common.Interfaces;
using Hutopy.Domain.Interfaces;
namespace Hutopy.Application.Users.Queries;
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public record GetCurrentUserQuery : IRequest<UserDto>;
@@ -21,6 +21,7 @@ public class GetCurrentUserQueryHandler(
.Where(x => x.ApplicationUserId == currentUserId.ToString())
.OrderBy(x => x.LastModified)
.ProjectTo<UserTransactionDto>(mapper.ConfigurationProvider)
.Where(x => x.IsConfirmed == true)
.ToListAsync(cancellationToken);
var user = new UserDto()
@@ -28,7 +29,9 @@ public class GetCurrentUserQueryHandler(
Id = currentUserId,
FirstName = identityUser?.FirstName ?? "",
LastName = identityUser?.LastName ?? "",
UserTransactions = transactions
UserName =identityUser?.UserName ?? "",
UserTransactions = transactions,
TotalBalance = transactions.Sum(x => x.Amount)
};
return user;

View File

@@ -1,13 +1,13 @@
namespace Hutopy.Application.Users.Queries;
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public class UserDto
{
public Guid Id { get; init; }
public required string FirstName { get; init; }
public required string LastName { get; init; }
public string UserName { get; init; } = String.Empty;
public List<UserTransactionDto> UserTransactions { get; init; } = [];
public required decimal TotalBalance { get; init; }
}

View File

@@ -1,15 +1,18 @@
using Hutopy.Domain.Entities;
namespace Hutopy.Application.Users.Queries;
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public class UserTransactionDto
{
public required decimal Amount { get; init; }
public string Currency { get; init; } = "cad";
public string TipMessage { get; init; } = string.Empty;
public DateTimeOffset Created { get; init; }
public bool IsConfirmed { get; init; }
private class Mapping : Profile
{
public Mapping()