From fe3803b4f8d29c953dde610b695d3f18e5e5963b Mon Sep 17 00:00:00 2001 From: "boxu.zheng" Date: Wed, 10 Jul 2024 08:14:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E7=94=A8=E6=88=B7=20?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Departments/IDepartmentAppService.cs | 1 + .../Departments/DepartmentAppService.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application.Contracts/Departments/IDepartmentAppService.cs b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application.Contracts/Departments/IDepartmentAppService.cs index d97d5d484..0af5cf24d 100644 --- a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application.Contracts/Departments/IDepartmentAppService.cs +++ b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application.Contracts/Departments/IDepartmentAppService.cs @@ -9,4 +9,5 @@ public interface IDepartmentAppService { Task GetByUsernameAsync(string username); Task UpdateAsync(DepartmentCreateInput input); + Task GetByUserIdAsync(string userId); } diff --git a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Departments/DepartmentAppService.cs b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Departments/DepartmentAppService.cs index b75291fc7..f546528a1 100644 --- a/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Departments/DepartmentAppService.cs +++ b/be/Hosts/Auth.Host/src/Win_in.Sfs.Auth.Application/Departments/DepartmentAppService.cs @@ -49,6 +49,27 @@ public class DepartmentAppService var deptDto = await GetByCodeAsync(departmentCode).ConfigureAwait(false); return deptDto; } + + [AllowAnonymous] + [HttpGet("by-userid")] + public virtual async Task GetByUserIdAsync(string userId) + { + var user = await _identityUserManager.FindByIdAsync(userId).ConfigureAwait(false); + if (user == null) + { + return null; + } + + var departmentCode = user.GetDepartmentCode(); + if (string.IsNullOrEmpty(departmentCode)) + { + return null; + } + + var deptDto = await GetByCodeAsync(departmentCode).ConfigureAwait(false); + return deptDto; + } + [AllowAnonymous] [HttpPost("update")] public virtual async Task UpdateAsync(DepartmentCreateInput input)