From 5cdfd9c63984ccd3f4518e2461ffe5761c2ffba1 Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Sat, 18 May 2024 00:04:10 -0400 Subject: [PATCH] #27 more info to myUser and userTransactions --- .../Users/Queries/GetCurrentUser/GetCurrentUser.cs | 7 +++++-- .../Users/Queries/GetCurrentUser/UserDto.cs | 8 ++++---- .../Queries/GetCurrentUser/UserTransactionDto.cs | 7 +++++-- src/Infrastructure/Services/UserService.cs | 3 +-- src/Web/Endpoints/GetMyUser.cs | 1 + src/Web/wwwroot/api/specification.json | 11 +++++++++++ 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs b/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs index 82dc2f8..cada50a 100644 --- a/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs +++ b/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs @@ -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; @@ -21,6 +21,7 @@ public class GetCurrentUserQueryHandler( .Where(x => x.ApplicationUserId == currentUserId.ToString()) .OrderBy(x => x.LastModified) .ProjectTo(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; diff --git a/src/Application/Users/Queries/GetCurrentUser/UserDto.cs b/src/Application/Users/Queries/GetCurrentUser/UserDto.cs index acece9c..a5e1b49 100644 --- a/src/Application/Users/Queries/GetCurrentUser/UserDto.cs +++ b/src/Application/Users/Queries/GetCurrentUser/UserDto.cs @@ -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 UserTransactions { get; init; } = []; + + public required decimal TotalBalance { get; init; } + } diff --git a/src/Application/Users/Queries/GetCurrentUser/UserTransactionDto.cs b/src/Application/Users/Queries/GetCurrentUser/UserTransactionDto.cs index e6103c7..f682df4 100644 --- a/src/Application/Users/Queries/GetCurrentUser/UserTransactionDto.cs +++ b/src/Application/Users/Queries/GetCurrentUser/UserTransactionDto.cs @@ -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() diff --git a/src/Infrastructure/Services/UserService.cs b/src/Infrastructure/Services/UserService.cs index 66dca70..8546a36 100644 --- a/src/Infrastructure/Services/UserService.cs +++ b/src/Infrastructure/Services/UserService.cs @@ -48,8 +48,7 @@ public class UserService(UserManager userManager, IHttpContextA public async Task GetCurrentUserAsync() { - // todo: Get the id of the user doing the request. - var currentUserId = contextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; + var currentUserId = contextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (string.IsNullOrEmpty(currentUserId)) { return null; diff --git a/src/Web/Endpoints/GetMyUser.cs b/src/Web/Endpoints/GetMyUser.cs index d7c78a6..feb5b50 100644 --- a/src/Web/Endpoints/GetMyUser.cs +++ b/src/Web/Endpoints/GetMyUser.cs @@ -1,4 +1,5 @@ using Hutopy.Application.Users.Queries; +using Hutopy.Application.Users.Queries.GetCurrentUser; namespace Hutopy.Web.Endpoints; diff --git a/src/Web/wwwroot/api/specification.json b/src/Web/wwwroot/api/specification.json index d0680de..1b42f2f 100644 --- a/src/Web/wwwroot/api/specification.json +++ b/src/Web/wwwroot/api/specification.json @@ -710,6 +710,10 @@ "items": { "$ref": "#/components/schemas/UserTransactionDto" } + }, + "totalBalance": { + "type": "number", + "format": "decimal" } } }, @@ -726,6 +730,13 @@ }, "tipMessage": { "type": "string" + }, + "created": { + "type": "string", + "format": "date-time" + }, + "isConfirmed": { + "type": "boolean" } } },