Refactor UpdateUserCommandHandler to include current user service and adjust user ID handling
This commit is contained in:
@@ -5,15 +5,21 @@ namespace FrontOffice.BFF.Application.UserCQ.Commands.UpdateUser;
|
|||||||
public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand, Unit>
|
public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand, Unit>
|
||||||
{
|
{
|
||||||
private readonly IApplicationContractContext _context;
|
private readonly IApplicationContractContext _context;
|
||||||
|
private readonly ICurrentUserService _currentUserService;
|
||||||
|
|
||||||
public UpdateUserCommandHandler(IApplicationContractContext context)
|
public UpdateUserCommandHandler(IApplicationContractContext context, ICurrentUserService currentUserService)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
_currentUserService = currentUserService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
|
public async Task<Unit> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
// var updatingUserRequest = new UpdateUserRequest();
|
var updatingUserRequest = request.Adapt<UpdateUserRequest>();
|
||||||
|
if (request.Id <= 0)
|
||||||
|
{
|
||||||
|
updatingUserRequest.Id = Convert.ToInt64(_currentUserService.UserId);
|
||||||
|
}
|
||||||
// var existUser = await _context.User.GetUserAsync(new GetUserRequest()
|
// var existUser = await _context.User.GetUserAsync(new GetUserRequest()
|
||||||
// {
|
// {
|
||||||
// Id = request.Id
|
// Id = request.Id
|
||||||
@@ -60,7 +66,7 @@ public class UpdateUserCommandHandler : IRequestHandler<UpdateUserCommand, Unit>
|
|||||||
// updatingUserRequest.SmsNotifications = request.SmsNotifications;
|
// updatingUserRequest.SmsNotifications = request.SmsNotifications;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
await _context.User.UpdateUserAsync(request: request.Adapt<UpdateUserRequest>(),
|
await _context.User.UpdateUserAsync(request: updatingUserRequest,
|
||||||
cancellationToken: cancellationToken);
|
cancellationToken: cancellationToken);
|
||||||
return Unit.Value;
|
return Unit.Value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,25 @@ using FrontOffice.BFF.Infrastructure.Services;
|
|||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.IdentityModel.Logging;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
namespace Microsoft.Extensions.DependencyInjection;
|
namespace Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
public static class ConfigureServices
|
public static class ConfigureServices
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services,
|
||||||
|
IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IApplicationContractContext, ApplicationContractContext>();
|
services.AddSingleton<IApplicationContractContext, ApplicationContractContext>();
|
||||||
services.AddSingleton<IKavenegarService, KavenegarService>();
|
services.AddSingleton<IKavenegarService, KavenegarService>();
|
||||||
services.AddInfrastructureGrpcServices(configuration);
|
services.AddInfrastructureGrpcServices(configuration);
|
||||||
|
|
||||||
#region AddAuthentication
|
#region AddAuthentication
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
IdentityModelEventSource.ShowPII = true;
|
||||||
|
#endif
|
||||||
var message = "";
|
var message = "";
|
||||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.AddJwtBearer(jwtBearerOptions =>
|
.AddJwtBearer(jwtBearerOptions =>
|
||||||
|
|||||||
Reference in New Issue
Block a user