#27 more info to myUser and userTransactions
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
using Hutopy.Application.Common.Interfaces;
|
using Hutopy.Application.Common.Interfaces;
|
||||||
using Hutopy.Domain.Interfaces;
|
using Hutopy.Domain.Interfaces;
|
||||||
|
|
||||||
namespace Hutopy.Application.Users.Queries;
|
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||||
|
|
||||||
public record GetCurrentUserQuery : IRequest<UserDto>;
|
public record GetCurrentUserQuery : IRequest<UserDto>;
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ public class GetCurrentUserQueryHandler(
|
|||||||
.Where(x => x.ApplicationUserId == currentUserId.ToString())
|
.Where(x => x.ApplicationUserId == currentUserId.ToString())
|
||||||
.OrderBy(x => x.LastModified)
|
.OrderBy(x => x.LastModified)
|
||||||
.ProjectTo<UserTransactionDto>(mapper.ConfigurationProvider)
|
.ProjectTo<UserTransactionDto>(mapper.ConfigurationProvider)
|
||||||
|
.Where(x => x.IsConfirmed == true)
|
||||||
.ToListAsync(cancellationToken);
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
var user = new UserDto()
|
var user = new UserDto()
|
||||||
@@ -28,7 +29,9 @@ public class GetCurrentUserQueryHandler(
|
|||||||
Id = currentUserId,
|
Id = currentUserId,
|
||||||
FirstName = identityUser?.FirstName ?? "",
|
FirstName = identityUser?.FirstName ?? "",
|
||||||
LastName = identityUser?.LastName ?? "",
|
LastName = identityUser?.LastName ?? "",
|
||||||
UserTransactions = transactions
|
UserName =identityUser?.UserName ?? "",
|
||||||
|
UserTransactions = transactions,
|
||||||
|
TotalBalance = transactions.Sum(x => x.Amount)
|
||||||
};
|
};
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
namespace Hutopy.Application.Users.Queries;
|
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||||
|
|
||||||
public class UserDto
|
public class UserDto
|
||||||
{
|
{
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; init; }
|
||||||
|
|
||||||
public required string FirstName { get; init; }
|
public required string FirstName { get; init; }
|
||||||
|
|
||||||
public required string LastName { get; init; }
|
public required string LastName { get; init; }
|
||||||
public string UserName { get; init; } = String.Empty;
|
public string UserName { get; init; } = String.Empty;
|
||||||
|
|
||||||
public List<UserTransactionDto> UserTransactions { get; init; } = [];
|
public List<UserTransactionDto> UserTransactions { get; init; } = [];
|
||||||
|
|
||||||
|
public required decimal TotalBalance { get; init; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using Hutopy.Domain.Entities;
|
using Hutopy.Domain.Entities;
|
||||||
|
|
||||||
namespace Hutopy.Application.Users.Queries;
|
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||||
|
|
||||||
public class UserTransactionDto
|
public class UserTransactionDto
|
||||||
{
|
{
|
||||||
@@ -10,6 +10,9 @@ public class UserTransactionDto
|
|||||||
|
|
||||||
public string TipMessage { get; init; } = string.Empty;
|
public string TipMessage { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTimeOffset Created { get; init; }
|
||||||
|
|
||||||
|
public bool IsConfirmed { get; init; }
|
||||||
private class Mapping : Profile
|
private class Mapping : Profile
|
||||||
{
|
{
|
||||||
public Mapping()
|
public Mapping()
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ public class UserService(UserManager<ApplicationUser> userManager, IHttpContextA
|
|||||||
|
|
||||||
public async Task<UserModel?> GetCurrentUserAsync()
|
public async Task<UserModel?> 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))
|
if (string.IsNullOrEmpty(currentUserId))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Hutopy.Application.Users.Queries;
|
using Hutopy.Application.Users.Queries;
|
||||||
|
using Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||||
|
|
||||||
namespace Hutopy.Web.Endpoints;
|
namespace Hutopy.Web.Endpoints;
|
||||||
|
|
||||||
|
|||||||
@@ -710,6 +710,10 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/components/schemas/UserTransactionDto"
|
"$ref": "#/components/schemas/UserTransactionDto"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"totalBalance": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "decimal"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -726,6 +730,13 @@
|
|||||||
},
|
},
|
||||||
"tipMessage": {
|
"tipMessage": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"created": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "date-time"
|
||||||
|
},
|
||||||
|
"isConfirmed": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user