diff --git a/src/Application/Common/Models/UserModel.cs b/src/Application/Common/Models/UserModel.cs index fb76755..ccff715 100644 --- a/src/Application/Common/Models/UserModel.cs +++ b/src/Application/Common/Models/UserModel.cs @@ -10,7 +10,7 @@ public class UserModel public string LastName { get; set; } = string.Empty; public string Occupation { get; set; } = 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; diff --git a/src/Application/Users/Commands/UpdateCurrentUserCommand.cs b/src/Application/Users/Commands/UpdateCurrentUserCommand.cs index 708ea6b..193d904 100644 --- a/src/Application/Users/Commands/UpdateCurrentUserCommand.cs +++ b/src/Application/Users/Commands/UpdateCurrentUserCommand.cs @@ -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 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(); + } + } } -public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIdentityService identityService) : +public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIdentityService identityService, IMapper mapper) : IRequestHandler { public async Task 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(request); + userModel.Id = identityUser.Id; - var result = await identityService.UpdateCurrentUserAsync(identityUser); + var result = await identityService.UpdateCurrentUserAsync(userModel); await context.SaveChangesAsync(cancellationToken); diff --git a/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs b/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs index 2fef51c..f8cc1ab 100644 --- a/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs +++ b/src/Application/Users/Queries/GetCurrentUser/GetCurrentUser.cs @@ -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 ?? "", diff --git a/src/Application/Users/Queries/GetCurrentUser/UserDto.cs b/src/Application/Users/Queries/GetCurrentUser/UserDto.cs index 24cb7fd..23dfaa8 100644 --- a/src/Application/Users/Queries/GetCurrentUser/UserDto.cs +++ b/src/Application/Users/Queries/GetCurrentUser/UserDto.cs @@ -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 UserTransactions { get; init; } = []; public IList UserRoles { get; init; } = []; public required decimal TotalBalance { get; init; } - } diff --git a/src/Infrastructure/Identity/IdentityService.cs b/src/Infrastructure/Identity/IdentityService.cs index d159de4..b0be8f2 100644 --- a/src/Infrastructure/Identity/IdentityService.cs +++ b/src/Infrastructure/Identity/IdentityService.cs @@ -97,7 +97,7 @@ public class IdentityService( applicationUser.FirstName = userModel.FirstName; applicationUser.LastName = userModel.LastName; applicationUser.Occupation = userModel.Occupation; - applicationUser.PhoneNumber = userModel.Phone; + applicationUser.PhoneNumber = userModel.PhoneNumber; applicationUser.BirthDate = userModel.BirthDate; applicationUser.Country = userModel.Country; applicationUser.City = userModel.City; @@ -147,7 +147,7 @@ public class IdentityService( LastName = response.LastName, Email = response.Email ?? string.Empty, Occupation = response.Occupation, - Phone = response.PhoneNumber ?? string.Empty, + PhoneNumber = response.PhoneNumber ?? string.Empty, BirthDate = response.BirthDate, Country = response.Country, City = response.City, @@ -197,7 +197,7 @@ public class IdentityService( LastName = response.LastName, Email = response.Email ?? string.Empty, Occupation = response.Occupation, - Phone = response.PhoneNumber ?? string.Empty, + PhoneNumber = response.PhoneNumber ?? string.Empty, BirthDate = response.BirthDate, Country = response.Country, City = response.City,