From d5dc0082b8d2abd51ecff4b53ccb641db0953801 Mon Sep 17 00:00:00 2001 From: esantangelo <enzo020895@gmail.com> Date: Wed, 25 Nov 2020 21:05:10 -0300 Subject: [PATCH] change endpoint GetMyCommunications to GetAllCommunications --- .../Controllers/CommunicationController.cs | 8 ++++---- .../Interfaces/ICommunicationService.cs | 2 +- .../Services/CommunicationService.cs | 14 ++++---------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs index 319dc2d..d5e9b2d 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs @@ -66,14 +66,14 @@ namespace Tsi1.Api.Controllers return Ok(); } - [Authorize(Roles = UserTypes.Student)] - [HttpGet("GetMyCommunications")] - public async Task<IActionResult> GetMyCommunications() + [Authorize(Roles = UserTypes.FacultyAdmin)] + [HttpGet("GetAllCommunications")] + public async Task<IActionResult> GetAllCommunications() { var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); - var result = await _communicationService.GetMyCommunications(userId, tenantId); + var result = await _communicationService.GetAllCommunications(tenantId); if (result.HasError) { diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs index dd182ca..b215bd9 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICommunicationService.cs @@ -13,7 +13,7 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<bool>> Delete(int communicationId); - Task<ServiceResult<List<CommunicationPreviewDto>>> GetMyCommunications(int userId, int tenantId); + Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllCommunications(int tenantId); Task<ServiceResult<List<CommunicationPreviewDto>>> GetCourseCommunications(int courseId, int tenantId); diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs index a29b593..039347c 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CommunicationService.cs @@ -62,12 +62,11 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<List<CommunicationPreviewDto>>> GetMyCommunications(int userId, int tenantId) + public async Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllCommunications(int tenantId) { var result = new ServiceResult<List<CommunicationPreviewDto>>(); - var user = await _context.Users.AsNoTracking().FirstOrDefaultAsync(x => x.Id == userId); - var tenant = await _context.Tenants.FirstOrDefaultAsync(x => x.Id == tenantId); + var tenant = await _context.Tenants.Include(x => x.Courses).FirstOrDefaultAsync(x => x.Id == tenantId); if (tenant == null) { @@ -75,18 +74,13 @@ namespace Tsi1.BusinessLayer.Services result.AddMessage(string.Format(ErrorMessages.TenantDoesNotExist, tenantId)); } - var courseIds = await _context.StudentCourses - .AsNoTracking() - .Where(x => x.StudentId == user.StudentId) - .Select(x => x.CourseId) - .ToListAsync(); + var courseIds = tenant.Courses.Select(x => x.Id); var communications = await _context.Communications .AsNoTracking() .Include(x => x.Tenant) .Include(x => x.Course) - .Where(x => (x.Tenant.Id == tenantId || courseIds.Contains(x.Course.Id)) - && x.ValidUntil >= DateTime.Now) + .Where(x => (x.Tenant.Id == tenantId || courseIds.Contains(x.Course.Id))) .ToListAsync(); result.Data = _mapper.Map<List<CommunicationPreviewDto>>(communications); -- GitLab