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)