From ce0a059ae62d65e7602711009eb928a0f1cda228 Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Wed, 25 Nov 2020 19:19:58 -0300
Subject: [PATCH] add endpoint GetAllGlobalCommunications
---
.../Controllers/CommunicationController.cs | 14 ++++++++++++++
.../Interfaces/ICommunicationService.cs | 1 +
.../Services/CommunicationService.cs | 15 +++++++++++++++
3 files changed, 30 insertions(+)
diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs
index 49152b6..319dc2d 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 4fa78a0..dd182ca 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 3acdbae..a29b593 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;
+ }
}
}
--
GitLab