diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs index e2abf687b6751ddbe19028264e3f2444c8b14269..1b3c61298f9767f9460ff360c5b6a997e6b24df6 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs @@ -332,6 +332,22 @@ namespace Tsi1.Api.Controllers return Ok(result.Data); } + [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)] + [HttpGet("GetAdmins")] + public async Task<IActionResult> GetAdmins() + { + var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); + var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value; + + var result = await _userService.GetAdmins(tenantId, userType); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)] [HttpGet("GetById/{userId}")] diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs index 1fbf3d8f98fe9bb37e97efba2d5df19c33f524bf..d503323a5aee281cb5fa54a7307829d7d90dcd6d 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IUserService.cs @@ -33,5 +33,6 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<List<UserPreviewDto>>> GetStudents(int tenantId); Task<ServiceResult<List<UserPreviewDto>>> GetProfessors(int tenantId); + Task<ServiceResult<List<UserPreviewDto>>> GetAdmins(int tenantId, string userType); } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs index f7710da8edce4efe65a498e4a24a6034da930c49..1e8f2b1174c63264ef9ac92bc91a87fc09400475 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/UserService.cs @@ -332,5 +332,31 @@ namespace Tsi1.BusinessLayer.Services return result; } + + public async Task<ServiceResult<List<UserPreviewDto>>> GetAdmins(int tenantId, string userType) + { + var result = new ServiceResult<List<UserPreviewDto>>(); + + var users = new List<User>(); + + if (userType == UserTypes.UdelarAdmin) + { + users = await _context.Users + .Where(x => x.UserType.Name == UserTypes.UdelarAdmin || x.UserType.Name == UserTypes.FacultyAdmin) + .ToListAsync(); + } + else + { + users = await _context.Users + .Where(x => x.UserType.Name == UserTypes.FacultyAdmin && x.TenantId == tenantId) + .ToListAsync(); + } + + var usersDto = _mapper.Map<List<UserPreviewDto>>(users); + + result.Data = usersDto; + + return result; + } } }