#27 added userTransactions
This commit is contained in:
37
src/Application/Users/Queries/GetCurrentUser.cs
Normal file
37
src/Application/Users/Queries/GetCurrentUser.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
12
src/Application/Users/Queries/UserDto.cs
Normal file
12
src/Application/Users/Queries/UserDto.cs
Normal 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; } = [];
|
||||
}
|
||||
20
src/Application/Users/Queries/UserTransactionDto.cs
Normal file
20
src/Application/Users/Queries/UserTransactionDto.cs
Normal 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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user