From 58816ca38374347bf92103f48a3aca2ca170176a Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 13 Dec 2025 18:38:08 +0330 Subject: [PATCH 1/2] feat: implement PmUserQueryService and integrate into AccountApplication for user ID retrieval --- 0_Framework/Application/AuthHelper.cs | 3 ++- 0_Framework/Application/AuthViewModel.cs | 5 ++++- .../AccountApplication.cs | 10 +++++++-- .../Services/User/PmUserQueryService.cs | 22 +++++++++++++++++++ .../PmUser/IPmUserQueryService.cs | 6 +++++ 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Services/User/PmUserQueryService.cs create mode 100644 Shared.Contracts/PmUser/IPmUserQueryService.cs diff --git a/0_Framework/Application/AuthHelper.cs b/0_Framework/Application/AuthHelper.cs index ef510830..12f820f8 100644 --- a/0_Framework/Application/AuthHelper.cs +++ b/0_Framework/Application/AuthHelper.cs @@ -198,7 +198,8 @@ public class AuthHelper : IAuthHelper new("workshopList",workshopBson), new("WorkshopSlug",slug), new("WorkshopId", account.WorkshopId.ToString()), - new("WorkshopName",account.WorkshopName??"") + new("WorkshopName",account.WorkshopName??""), + new("pm.userId", account.PmUserId?.ToString() ?? "0"), }; diff --git a/0_Framework/Application/AuthViewModel.cs b/0_Framework/Application/AuthViewModel.cs index d419bd67..aebda696 100644 --- a/0_Framework/Application/AuthViewModel.cs +++ b/0_Framework/Application/AuthViewModel.cs @@ -27,10 +27,12 @@ public class AuthViewModel #endregion public long SubAccountId { get; set; } + public long? PmUserId { get; set; } public AuthViewModel(long id, long roleId, string fullname, string username, string mobile,string profilePhoto, - List permissions, string roleName, string adminAreaPermission, string clientAriaPermission, int? positionValue, long subAccountId = 0) + List permissions, string roleName, string adminAreaPermission, string clientAriaPermission, int? positionValue, + long subAccountId = 0,long? pmUserId = null) { Id = id; RoleId = roleId; @@ -44,6 +46,7 @@ public class AuthViewModel ClientAriaPermission = clientAriaPermission; PositionValue = positionValue; SubAccountId = subAccountId; + PmUserId = pmUserId; } public AuthViewModel() diff --git a/AccountManagement.Application/AccountApplication.cs b/AccountManagement.Application/AccountApplication.cs index bba09128..8676a795 100644 --- a/AccountManagement.Application/AccountApplication.cs +++ b/AccountManagement.Application/AccountApplication.cs @@ -34,6 +34,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using AccountManagement.Application.Contracts.ProgramManager; +using Shared.Contracts.PmUser; using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; //using AccountManagement.Domain.RoleAgg; @@ -58,9 +59,10 @@ public class AccountApplication : IAccountApplication private readonly ISubAccountPermissionSubtitle1Repository _accountPermissionSubtitle1Repository; private readonly IPmUserRepository _pmUserRepository; private readonly IUnitOfWork _unitOfWork; + private readonly IPmUserQueryService _pmUserQueryService; public AccountApplication(IAccountRepository accountRepository, IPasswordHasher passwordHasher, - IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository, IAccountLeftworkRepository accountLeftworkRepository, IWorkshopRepository workshopRepository, ISubAccountRepository subAccountRepository, ISubAccountRoleRepository subAccountRoleRepository, IWorkshopSubAccountRepository workshopSubAccountRepository, ISubAccountPermissionSubtitle1Repository accountPermissionSubtitle1Repository, IUnitOfWork unitOfWork, IPmUserRepository pmUserRepository) + IFileUploader fileUploader, IAuthHelper authHelper, IRoleRepository roleRepository, IWorker worker, ISmsService smsService, ICameraAccountRepository cameraAccountRepository, IPositionRepository positionRepository, IAccountLeftworkRepository accountLeftworkRepository, IWorkshopRepository workshopRepository, ISubAccountRepository subAccountRepository, ISubAccountRoleRepository subAccountRoleRepository, IWorkshopSubAccountRepository workshopSubAccountRepository, ISubAccountPermissionSubtitle1Repository accountPermissionSubtitle1Repository, IUnitOfWork unitOfWork, IPmUserRepository pmUserRepository, IPmUserQueryService pmUserQueryService) { _authHelper = authHelper; _roleRepository = roleRepository; @@ -75,6 +77,7 @@ public class AccountApplication : IAccountApplication _accountPermissionSubtitle1Repository = accountPermissionSubtitle1Repository; _unitOfWork = unitOfWork; _pmUserRepository = pmUserRepository; + _pmUserQueryService = pmUserQueryService; _fileUploader = fileUploader; _passwordHasher = passwordHasher; _accountRepository = accountRepository; @@ -463,8 +466,11 @@ public class AccountApplication : IAccountApplication { positionValue = null; } + var pmUserId = _pmUserQueryService.GetCurrentPmUserIdFromAccountId(account.id).GetAwaiter().GetResult(); var authViewModel = new AuthViewModel(account.id, account.RoleId, account.Fullname - , account.Username, account.Mobile, account.ProfilePhoto, permissions, account.RoleName, account.AdminAreaPermission, account.ClientAriaPermission, positionValue); + , account.Username, account.Mobile, account.ProfilePhoto, + permissions, account.RoleName, account.AdminAreaPermission, + account.ClientAriaPermission, positionValue,0,pmUserId); if (account.ClientAriaPermission == "true" && account.AdminAreaPermission == "false" && account.IsActiveString == "true") diff --git a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Services/User/PmUserQueryService.cs b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Services/User/PmUserQueryService.cs new file mode 100644 index 00000000..80e43524 --- /dev/null +++ b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/Services/User/PmUserQueryService.cs @@ -0,0 +1,22 @@ +using GozareshgirProgramManager.Application.Modules.Users.Queries.GetSingleUser; +using MediatR; +using Shared.Contracts.PmUser; + +namespace GozareshgirProgramManager.Infrastructure.Services.User; + +public class PmUserQueryService : IPmUserQueryService +{ + public readonly IMediator _mediator; + + public PmUserQueryService(IMediator mediator) + { + _mediator = mediator; + } + + public async Task GetCurrentPmUserIdFromAccountId(long accountId) + { + var query = new GetSingleUserQuery(accountId.ToString()); + var result = await _mediator.Send(query); + return result.Data?.AccountId ?? null; + } +} \ No newline at end of file diff --git a/Shared.Contracts/PmUser/IPmUserQueryService.cs b/Shared.Contracts/PmUser/IPmUserQueryService.cs new file mode 100644 index 00000000..479355de --- /dev/null +++ b/Shared.Contracts/PmUser/IPmUserQueryService.cs @@ -0,0 +1,6 @@ +namespace Shared.Contracts.PmUser; + +public interface IPmUserQueryService +{ + Task GetCurrentPmUserIdFromAccountId(long accountId); +} \ No newline at end of file From a52e31398478e1220e63295dc04e351d845029ca Mon Sep 17 00:00:00 2001 From: mahan Date: Sat, 13 Dec 2025 18:50:39 +0330 Subject: [PATCH 2/2] feat: register PmUserQueryService in Dependency Injection for user queries --- .../DependencyInjection.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/DependencyInjection.cs b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/DependencyInjection.cs index ae816e1a..8451e848 100644 --- a/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/DependencyInjection.cs +++ b/ProgramManager/src/Infrastructure/GozareshgirProgramManager.Infrastructure/DependencyInjection.cs @@ -20,12 +20,14 @@ using GozareshgirProgramManager.Infrastructure.Persistence.Context; using GozareshgirProgramManager.Infrastructure.Persistence.Repositories; using GozareshgirProgramManager.Infrastructure.Services.Authentication; using GozareshgirProgramManager.Infrastructure.Services.Role; +using GozareshgirProgramManager.Infrastructure.Services.User; using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Shared.Contracts.PmRole.Commands; using Shared.Contracts.PmRole.Queries; +using Shared.Contracts.PmUser; namespace GozareshgirProgramManager.Infrastructure; @@ -93,6 +95,7 @@ public static class DependencyInjection services.AddTransient(); services.AddTransient(); + services.AddTransient(); #endregion