Adds edition of user profile

This commit is contained in:
2024-09-03 20:59:43 -04:00
parent 012ad7fcf4
commit f12418bc79
28 changed files with 1398 additions and 182 deletions

View File

@@ -3,14 +3,13 @@ namespace Hutopy.Application.Common.Models;
public class UserModel
{
public Guid Id { get; set; }
public string UserName { get; init; } = null!;
public string Username { get; init; } = null!;
public string? Alias { get; init; }
public string? PortraitUrl { get; init; }
public string? FirstName { get; init; }
public string? LastName { get; init; }
public string? Occupation { get; init; }
public string? Firstname { get; init; }
public string? Lastname { get; init; }
public string? Email { get; init; }
public string? PhoneNumber { get; init; }
public string? BirthDate { get; init; }
public DateTime? BirthDate { get; init; }
public string? Address { get; init; }
}

View File

@@ -1,50 +0,0 @@
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public record GetCurrentUserQuery : IRequest<UserDto>;
public class GetCurrentUserQueryHandler(
IApplicationDbContext context,
IMapper mapper,
IIdentityService identityService
)
: IRequestHandler<GetCurrentUserQuery, UserDto>
{
public async Task<UserDto?> Handle(GetCurrentUserQuery request, CancellationToken cancellationToken)
{
var userModel = await identityService.GetCurrentUserAsync();
if (userModel is null) return null;
var transactions = await context
.UserTransactions
.Where(x => x.ApplicationUserId == userModel.Id)
.OrderBy(x => x.LastModifiedAt)
.ProjectTo<UserTransactionDto>(mapper.ConfigurationProvider)
.Where(x => x.IsConfirmed == true)
.ToListAsync(cancellationToken);
var roles = await identityService.GetCurrentUserRolesAsync();
var user = new UserDto
{
Id = userModel.Id,
Alias = userModel.Alias,
PortraitUrl = userModel.PortraitUrl,
FirstName = userModel.FirstName,
LastName = userModel.LastName,
UserName = userModel.UserName,
Occupation = userModel.Occupation,
PhoneNumber = userModel.PhoneNumber,
Email = userModel.Email,
BirthDate = userModel.BirthDate,
Address = userModel.Address,
UserTransactions = transactions,
TotalBalance = transactions.Sum(x => x.Amount),
UserRoles = roles,
};
return user;
}
}

View File

@@ -1,23 +0,0 @@
using Hutopy.Application.AzureBlobStorage.Constants;
using Hutopy.Application.Common.Interfaces;
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public record GetCurrentUserProfilePictureQuery : IRequest<Stream>;
public class GetCurrentUserProfilePictureQueryHandler(
IIdentityService identityService,
IBlobStorage blobStorage
)
: IRequestHandler<GetCurrentUserProfilePictureQuery, Stream>
{
public async Task<Stream> Handle(GetCurrentUserProfilePictureQuery request, CancellationToken cancellationToken)
{
var identityUser = await identityService.GetCurrentUserAsync();
return await blobStorage.DownloadFileAsync(
ContainerNames.Users,
$"{identityUser.Id.ToString()}/{SubDirectoryNames.Profile}/{CommonFileNames.ProfilePicture}",
cancellationToken);
}
}

View File

@@ -1,19 +0,0 @@
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
public class UserDto
{
public Guid Id { get; init; }
public IList<string> UserRoles { get; init; } = [];
public string UserName { get; init; } = null!;
public string? Alias { get; init; }
public string? PortraitUrl { get; init; }
public string? FirstName { get; init; }
public string? LastName { get; init; }
public string? Occupation { get; init; }
public string? Email { get; init; }
public string? PhoneNumber { get; init; }
public string? BirthDate { get; init; }
public string? Address { get; init; }
public List<UserTransactionDto> UserTransactions { get; init; } = [];
public required decimal TotalBalance { get; init; }
}

View File

@@ -1,23 +0,0 @@
using Hutopy.Domain.Entities;
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()
{
CreateMap<UserTransaction, UserTransactionDto>();
}
}
}

View File

@@ -17,9 +17,8 @@ public static class UserDtoExtensions
new()
{
Id = model.Id,
FirstName = model.FirstName,
LastName = model.LastName,
UserName = model.UserName,
Occupation = model.Occupation
FirstName = model.Firstname,
LastName = model.Lastname,
UserName = model.Username
};
}