From b677aff165541b14f147cc430f42b73fb75ff0b1 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Fri, 14 Nov 2025 08:13:58 +0330 Subject: [PATCH] Refactor UpdateUserCommandHandler and add authorization to VerifyOtpToken method --- .../UpdateUser/UpdateUserCommandHandler.cs | 89 +++++++++---------- .../Services/UserService.cs | 2 + 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs b/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs index 7704731..1de4a6a 100644 --- a/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs +++ b/src/FrontOffice.BFF.Application/UserCQ/Commands/UpdateUser/UpdateUserCommandHandler.cs @@ -13,53 +13,52 @@ public class UpdateUserCommandHandler : IRequestHandler public async Task Handle(UpdateUserCommand request, CancellationToken cancellationToken) { - var updatingUserRequest = new UpdateUserRequest(); - var existUser = await _context.User.GetUserAsync(new GetUserRequest() - { - Id = request.Id - }, cancellationToken: cancellationToken); - if (existUser == null) - throw new NotFoundException("User not found"); - - if (!string.IsNullOrEmpty(request.FirstName)) - { - updatingUserRequest.FirstName = request.FirstName; - } - - if (!string.IsNullOrEmpty(request.LastName)) - { - updatingUserRequest.LastName = request.LastName; - } - - if (!string.IsNullOrEmpty(request.NationalCode)) - { - updatingUserRequest.NationalCode = request.NationalCode; - } - if (request.BirthDate.HasValue) - { - updatingUserRequest.BirthDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.BirthDate.Value, DateTimeKind.Utc));; - } - if (!string.IsNullOrEmpty(request.AvatarPath)) - { - updatingUserRequest.AvatarPath = request.AvatarPath; - } - // if (request.AvatarFile!= null) + // var updatingUserRequest = new UpdateUserRequest(); + // var existUser = await _context.User.GetUserAsync(new GetUserRequest() // { + // Id = request.Id + // }, cancellationToken: cancellationToken); + // if (existUser == null) + // throw new NotFoundException("User not found"); + // + // if (!string.IsNullOrEmpty(request.FirstName)) + // { + // updatingUserRequest.FirstName = request.FirstName; + // } + // + // if (!string.IsNullOrEmpty(request.LastName)) + // { + // updatingUserRequest.LastName = request.LastName; + // } + // if (!string.IsNullOrEmpty(request.NationalCode)) + // { + // updatingUserRequest.NationalCode = request.NationalCode; + // } + // if (request.BirthDate.HasValue) + // { + // updatingUserRequest.BirthDate = Timestamp.FromDateTime(DateTime.SpecifyKind(request.BirthDate.Value, DateTimeKind.Utc));; + // } + // if (!string.IsNullOrEmpty(request.AvatarPath)) + // { + // updatingUserRequest.AvatarPath = request.AvatarPath; + // } + // // if (request.AvatarFile!= null) + // // { + // // } + // if (request.PushNotifications!=existUser.PushNotifications) + // { + // updatingUserRequest.PushNotifications = request.PushNotifications; + // } + // + // if (request.EmailNotifications!=existUser.EmailNotifications) + // { + // updatingUserRequest.EmailNotifications = request.EmailNotifications; + // } + // + // if (request.SmsNotifications!=existUser.SmsNotifications) + // { + // updatingUserRequest.SmsNotifications = request.SmsNotifications; // } - if (request.PushNotifications!=existUser.PushNotifications) - { - updatingUserRequest.PushNotifications = request.PushNotifications; - } - - if (request.EmailNotifications!=existUser.EmailNotifications) - { - updatingUserRequest.EmailNotifications = request.EmailNotifications; - } - - if (request.SmsNotifications!=existUser.SmsNotifications) - { - updatingUserRequest.SmsNotifications = request.SmsNotifications; - } await _context.User.UpdateUserAsync(request: request.Adapt(), cancellationToken: cancellationToken); diff --git a/src/FrontOffice.BFF.WebApi/Services/UserService.cs b/src/FrontOffice.BFF.WebApi/Services/UserService.cs index f3e64af..48c5224 100644 --- a/src/FrontOffice.BFF.WebApi/Services/UserService.cs +++ b/src/FrontOffice.BFF.WebApi/Services/UserService.cs @@ -39,10 +39,12 @@ public class UserService : UserContract.UserContractBase { return await _dispatchRequestToCQRS.Handle(request, context); } + [Authorize(Roles = "user")] public override async Task VerifyOtpToken(VerifyOtpTokenRequest request, ServerCallContext context) { return await _dispatchRequestToCQRS.Handle(request, context); } + [Authorize(Roles = "user")] public override async Task AdminGetJwtToken(AdminGetJwtTokenRequest request, ServerCallContext context) { return await _dispatchRequestToCQRS.Handle(request, context);