diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs index 49152b69e8858e801ddd1517b51f30100fa0bce5..319dc2d8266a46e2e6be87754a1cefe6a5db4183 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs @@ -119,6 +119,20 @@ namespace Tsi1.Api.Controllers return Ok(result.Data); } + [Authorize(Roles = UserTypes.UdelarAdmin)] + [HttpGet("GetAllGlobalCommunications")] + public async Task<IActionResult> GetAllGlobalCommunications() + { + var result = await _communicationService.GetAllGlobalCommunications(); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + [Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)] [HttpDelete("Delete/{communicationId}")] public async Task<IActionResult> Delete(int communicationId) diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs index 4fa78a04a6ae0604d6baf2db30755575f6e9a33a..dd182cad2ea7bf9fde21cf11838d1b2a8a5e7ee1 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs @@ -20,5 +20,6 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<List<CommunicationPreviewDto>>> GetGlobalCommunications(int tenantId); Task<ServiceResult<bool>> TenantValidation(int tenantId, int courseId); + Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllGlobalCommunications(); } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs index 3acdbae79a68447975539a4e428f712f4ee8b60e..a29b593e601a0dcceabc85e459ddfba2dfd4b0be 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs @@ -190,5 +190,20 @@ namespace Tsi1.BusinessLayer.Services return result; } + + public async Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllGlobalCommunications() + { + var result = new ServiceResult<List<CommunicationPreviewDto>>(); + + var communications = await _context.Communications + .AsNoTracking() + .Include(x => x.Tenant) + .Where(x => x.IsGlobal) + .ToListAsync(); + + result.Data = _mapper.Map<List<CommunicationPreviewDto>>(communications); + + return result; + } } }