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

@@ -10,7 +10,7 @@ public class UserModel
public string LastName { get; set; } = string.Empty; public string LastName { get; set; } = string.Empty;
public string Occupation { get; set; } = string.Empty; public string Occupation { get; set; } = string.Empty;
public string Email { 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 BirthDate { get; init; } = string.Empty;
public string Country { get; init; } = string.Empty; public string Country { get; init; } = string.Empty;
public string City { get; init; } = string.Empty; public string City { get; init; } = string.Empty;

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; using Hutopy.Application.Users.Models;
namespace Hutopy.Application.Users.Commands; namespace Hutopy.Application.Users.Commands;
@@ -17,9 +19,18 @@ public class UpdateCurrentUserCommand : IRequest<string>
public required string Description { get; init; } public required string Description { get; init; }
public required SocialNetworksModel SocialNetworks { get; init; } public required SocialNetworksModel SocialNetworks { get; init; }
public required ProfileColorsModel ProfileColors { 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> IRequestHandler<UpdateCurrentUserCommand, string>
{ {
public async Task<string> Handle(UpdateCurrentUserCommand request, CancellationToken cancellationToken) public async Task<string> Handle(UpdateCurrentUserCommand request, CancellationToken cancellationToken)
@@ -28,7 +39,10 @@ public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIde
if (identityUser?.Id is null) return string.Empty; if (identityUser?.Id is null) return string.Empty;
var result = await identityService.UpdateCurrentUserAsync(identityUser); var userModel = mapper.Map<UserModel>(request);
userModel.Id = identityUser.Id;
var result = await identityService.UpdateCurrentUserAsync(userModel);
await context.SaveChangesAsync(cancellationToken); await context.SaveChangesAsync(cancellationToken);

View File

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

View File

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

View File

@@ -97,7 +97,7 @@ public class IdentityService(
applicationUser.FirstName = userModel.FirstName; applicationUser.FirstName = userModel.FirstName;
applicationUser.LastName = userModel.LastName; applicationUser.LastName = userModel.LastName;
applicationUser.Occupation = userModel.Occupation; applicationUser.Occupation = userModel.Occupation;
applicationUser.PhoneNumber = userModel.Phone; applicationUser.PhoneNumber = userModel.PhoneNumber;
applicationUser.BirthDate = userModel.BirthDate; applicationUser.BirthDate = userModel.BirthDate;
applicationUser.Country = userModel.Country; applicationUser.Country = userModel.Country;
applicationUser.City = userModel.City; applicationUser.City = userModel.City;
@@ -147,7 +147,7 @@ public class IdentityService(
LastName = response.LastName, LastName = response.LastName,
Email = response.Email ?? string.Empty, Email = response.Email ?? string.Empty,
Occupation = response.Occupation, Occupation = response.Occupation,
Phone = response.PhoneNumber ?? string.Empty, PhoneNumber = response.PhoneNumber ?? string.Empty,
BirthDate = response.BirthDate, BirthDate = response.BirthDate,
Country = response.Country, Country = response.Country,
City = response.City, City = response.City,
@@ -197,7 +197,7 @@ public class IdentityService(
LastName = response.LastName, LastName = response.LastName,
Email = response.Email ?? string.Empty, Email = response.Email ?? string.Empty,
Occupation = response.Occupation, Occupation = response.Occupation,
Phone = response.PhoneNumber ?? string.Empty, PhoneNumber = response.PhoneNumber ?? string.Empty,
BirthDate = response.BirthDate, BirthDate = response.BirthDate,
Country = response.Country, Country = response.Country,
City = response.City, City = response.City,