From 13b4778f01c366728f94565290c4eee2398ab299 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Sun, 16 Nov 2025 17:29:30 +0330 Subject: [PATCH] Refactor AcceptContractCommandHandler to return AcceptContractResponseDto and integrate OTP verification --- .../AcceptContractCommandHandler.cs | 19 ++++++++++++++++--- .../Services/ApplicationContractContext.cs | 3 ++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/FrontOffice.BFF.Application/UserCQ/Commands/AcceptContract/AcceptContractCommandHandler.cs b/src/FrontOffice.BFF.Application/UserCQ/Commands/AcceptContract/AcceptContractCommandHandler.cs index 1b9ebc6..f47e873 100644 --- a/src/FrontOffice.BFF.Application/UserCQ/Commands/AcceptContract/AcceptContractCommandHandler.cs +++ b/src/FrontOffice.BFF.Application/UserCQ/Commands/AcceptContract/AcceptContractCommandHandler.cs @@ -1,7 +1,9 @@ +using CMSMicroservice.Protobuf.Protos.OtpToken; using CMSMicroservice.Protobuf.Protos.UserContract; +using FrontOffice.BFF.Application.UserCQ.Commands.VerifyOtpToken; namespace FrontOffice.BFF.Application.UserCQ.Commands.AcceptContract; -public class AcceptContractCommandHandler : IRequestHandler +public class AcceptContractCommandHandler : IRequestHandler { private readonly IApplicationContractContext _context; private readonly ICurrentUserService _currentUserService; @@ -12,7 +14,7 @@ public class AcceptContractCommandHandler : IRequestHandler Handle(AcceptContractCommand request, CancellationToken cancellationToken) + public async Task Handle(AcceptContractCommand request, CancellationToken cancellationToken) { await _context.UserContract.CreateNewUserContractAsync(new CreateNewUserContractRequest() { @@ -21,6 +23,17 @@ public class AcceptContractCommandHandler : IRequestHandler(), cancellationToken: cancellationToken); + var result = response.Adapt(); + if (response.Success && response.UserId.HasValue && response.UserId.Value > 0) + { + var token = await _context.User.GetJwtTokenAsync(request: new() + { + Id = response.UserId.Value + }, cancellationToken: cancellationToken); + + result.Token = token?.Token; + } + return result; } } diff --git a/src/FrontOffice.BFF.Infrastructure/Services/ApplicationContractContext.cs b/src/FrontOffice.BFF.Infrastructure/Services/ApplicationContractContext.cs index 77ff925..7a5072c 100644 --- a/src/FrontOffice.BFF.Infrastructure/Services/ApplicationContractContext.cs +++ b/src/FrontOffice.BFF.Infrastructure/Services/ApplicationContractContext.cs @@ -2,6 +2,7 @@ using CMSMicroservice.Protobuf.Protos.OtpToken; using CMSMicroservice.Protobuf.Protos.Package; using CMSMicroservice.Protobuf.Protos.User; using CMSMicroservice.Protobuf.Protos.UserAddress; +using CMSMicroservice.Protobuf.Protos.UserContract; using CMSMicroservice.Protobuf.Protos.UserOrder; using FrontOffice.BFF.Application.Common.Interfaces; using Microsoft.Extensions.DependencyInjection; @@ -43,7 +44,7 @@ public class ApplicationContractContext : IApplicationContractContext public PackageContract.PackageContractClient Package => GetService(); public UserContract.UserContractClient User => GetService(); - + public UserContractContract.UserContractContractClient UserContract => GetService(); public UserAddressContract.UserAddressContractClient UserAddress => GetService(); public UserOrderContract.UserOrderContractClient UserOrder => GetService();