Mapping + changed Phone to PhoneNumber

This commit is contained in:
Dominic Villemure
2024-06-30 15:48:26 -04:00
parent 90d76c32ce
commit 041b8178ac
5 changed files with 23 additions and 10 deletions

View File

@@ -1,4 +1,6 @@
using Hutopy.Application.Common.Interfaces;
using System.ComponentModel.DataAnnotations.Schema;
using Hutopy.Application.Common.Interfaces;
using Hutopy.Application.Common.Models;
using Hutopy.Application.Users.Models;
namespace Hutopy.Application.Users.Commands;
@@ -17,9 +19,18 @@ public class UpdateCurrentUserCommand : IRequest<string>
public required string Description { get; init; }
public required SocialNetworksModel SocialNetworks { get; init; }
public required ProfileColorsModel ProfileColors { get; init; }
[NotMapped]
private class Mapping : Profile
{
public Mapping()
{
CreateMap<UpdateCurrentUserCommand, UserModel>();
}
}
}
public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIdentityService identityService) :
public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIdentityService identityService, IMapper mapper) :
IRequestHandler<UpdateCurrentUserCommand, string>
{
public async Task<string> Handle(UpdateCurrentUserCommand request, CancellationToken cancellationToken)
@@ -27,8 +38,11 @@ public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIde
var identityUser = await identityService.GetCurrentUserAsync();
if (identityUser?.Id is null) return string.Empty;
var userModel = mapper.Map<UserModel>(request);
userModel.Id = identityUser.Id;
var result = await identityService.UpdateCurrentUserAsync(identityUser);
var result = await identityService.UpdateCurrentUserAsync(userModel);
await context.SaveChangesAsync(cancellationToken);

View File

@@ -32,7 +32,7 @@ public class GetCurrentUserQueryHandler(
LastName = identityUser.LastName ?? "",
UserName = identityUser.UserName ?? "",
Occupation = identityUser.Occupation ?? "",
Phone = identityUser.Phone ?? "",
PhoneNumber = identityUser.PhoneNumber ?? "",
Email = identityUser.Email ?? "",
BirthDate = identityUser.BirthDate ?? "",
Country = identityUser.Country ?? "",

View File

@@ -10,7 +10,7 @@ public class UserDto
public string UserName { get; init; } = string.Empty;
public string Occupation { get; init; } = string.Empty;
public string Email { get; init; } = string.Empty;
public string Phone { get; init; } = string.Empty;
public string PhoneNumber { get; init; } = string.Empty;
public string BirthDate { get; init; } = string.Empty;
public string Country { get; init; } = string.Empty;
public string City { get; init; } = string.Empty;
@@ -23,5 +23,4 @@ public class UserDto
public List<UserTransactionDto> UserTransactions { get; init; } = [];
public IList<string> UserRoles { get; init; } = [];
public required decimal TotalBalance { get; init; }
}