update-current-user WIP
This commit is contained in:
committed by
Jonathan Bourdon
parent
72e243cf84
commit
5282fcfd49
40
src/Application/Users/Commands/UpdateCurrentUserCommand.cs
Normal file
40
src/Application/Users/Commands/UpdateCurrentUserCommand.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Users.Models;
|
||||
|
||||
namespace Hutopy.Application.Users.Commands;
|
||||
|
||||
public class UpdateCurrentUserCommand : IRequest<string>
|
||||
{
|
||||
public required string FirstName { get; init; }
|
||||
public required string LastName { get; init; }
|
||||
public required string Occupation { get; init; }
|
||||
public required string PhoneNumber { get; init; }
|
||||
public required string BirthDate { get; init; }
|
||||
public required string Country { get; init; }
|
||||
public required string City { get; init; }
|
||||
public required string Address { get; init; }
|
||||
public required string About { get; init; }
|
||||
public required string Description { get; init; }
|
||||
public required SocialNetworksModel SocialNetworks { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIdentityService identityService) :
|
||||
IRequestHandler<UpdateCurrentUserCommand, string>
|
||||
{
|
||||
public async Task<string> Handle(UpdateCurrentUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var identityUser = await identityService.GetCurrentUserAsync();
|
||||
|
||||
if (identityUser?.Id is null) return string.Empty;
|
||||
|
||||
var result = await identityService.UpdateCurrentUserAsync(identityUser.Id, request.FirstName, request.LastName,
|
||||
request.Occupation, request.PhoneNumber, request.BirthDate,
|
||||
request.Country, request.City, request.Address, request.About,
|
||||
request.Description, request.SocialNetworks);
|
||||
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return result.GetValueOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
13
src/Application/Users/Models/SocialNetworksModel.cs
Normal file
13
src/Application/Users/Models/SocialNetworksModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Hutopy.Application.Users.Models;
|
||||
|
||||
public class SocialNetworksModel
|
||||
{
|
||||
public string FacebookUrl { get; init; } = String.Empty;
|
||||
public string InstagramUrl { get; init; } = String.Empty;
|
||||
public string XUrl { get; init; } = String.Empty;
|
||||
public string LinkedInUrl { get; init; } = String.Empty;
|
||||
public string TikTokUrl { get; init; } = String.Empty;
|
||||
public string YoutubeUrl { get; init; } = String.Empty;
|
||||
public string RedditUrl { get; init; } = String.Empty;
|
||||
public string YourWebsiteUrl { get; init; } = String.Empty;
|
||||
}
|
||||
@@ -28,12 +28,22 @@ public class GetCurrentUserQueryHandler(
|
||||
var user = new UserDto
|
||||
{
|
||||
Id = currentUserId,
|
||||
FirstName = identityUser?.FirstName ?? "",
|
||||
LastName = identityUser?.LastName ?? "",
|
||||
UserName = identityUser?.UserName ?? "",
|
||||
FirstName = identityUser.FirstName ?? "",
|
||||
LastName = identityUser.LastName ?? "",
|
||||
UserName = identityUser.UserName ?? "",
|
||||
Occupation = identityUser.Occupation ?? "",
|
||||
Phone = identityUser.Phone ?? "",
|
||||
Email = identityUser.Email ?? "",
|
||||
BirthDate = identityUser.BirthDate ?? "",
|
||||
Country = identityUser.Country ?? "",
|
||||
City = identityUser.City ?? "",
|
||||
Address = identityUser.Address ?? "",
|
||||
About = identityUser.About ?? "",
|
||||
Description = identityUser.Description ?? "",
|
||||
SocialNetworks = identityUser.SocialNetworks,
|
||||
UserTransactions = transactions,
|
||||
TotalBalance = transactions.Sum(x => x.Amount),
|
||||
UserRoles = roles
|
||||
UserRoles = roles,
|
||||
};
|
||||
|
||||
return user;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using Hutopy.Application.Users.Models;
|
||||
|
||||
namespace Hutopy.Application.Users.Queries.GetCurrentUser;
|
||||
|
||||
public class UserDto
|
||||
@@ -6,6 +8,16 @@ public class UserDto
|
||||
public required string FirstName { get; init; }
|
||||
public required string LastName { get; init; }
|
||||
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 BirthDate { get; init; } = String.Empty;
|
||||
public string Country { get; init; } = String.Empty;
|
||||
public string City { get; init; } = String.Empty;
|
||||
public string Address { get; init; } = String.Empty;
|
||||
public string About { get; init; } = String.Empty;
|
||||
public string Description { get; init; } = String.Empty;
|
||||
public SocialNetworksModel SocialNetworks { get; init; } = new();
|
||||
public List<UserTransactionDto> UserTransactions { get; init; } = [];
|
||||
public IList<string> UserRoles { get; init; } = [];
|
||||
public required decimal TotalBalance { get; init; }
|
||||
|
||||
Reference in New Issue
Block a user