diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs index 319dc2d8266a46e2e6be87754a1cefe6a5db4183..d5e9b2d82a6414c62badc6a90ce2e3b82bcd9807 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 dd182cad2ea7bf9fde21cf11838d1b2a8a5e7ee1..b215bd914da1d507644e6d12862bde4c28233b3c 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 a29b593e601a0dcceabc85e459ddfba2dfd4b0be..039347c78ed142a825b3d014f4520398d4b1d5f0 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);