From 32259137e1049ccb39fde9814462b24e15fbee7b Mon Sep 17 00:00:00 2001 From: esantangelo <enzo020895@gmail.com> Date: Sat, 28 Nov 2020 19:19:06 -0300 Subject: [PATCH] reports --- .../Tsi1.Api/Controllers/TenantController.cs | 41 +++++++++++--- .../Tsi1.Api/Controllers/UserController.cs | 2 +- Tsi1.Api/Tsi1.Api/SignalR/VideoHub.cs | 2 - .../Dtos/RegistrationDto.cs | 15 +++++ .../Dtos/TenantPreviewDto.cs | 2 - .../Helpers/MappingProfile.cs | 6 +- .../Interfaces/ITenantService.cs | 6 +- .../Services/TenantService.cs | 55 +++++++++++++++++-- 8 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 Tsi1.Api/Tsi1.BusinessLayer/Dtos/RegistrationDto.cs diff --git a/Tsi1.Api/Tsi1.Api/Controllers/TenantController.cs b/Tsi1.Api/Tsi1.Api/Controllers/TenantController.cs index 9b59731..1204626 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/TenantController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/TenantController.cs @@ -17,12 +17,9 @@ namespace Tsi1.Api.Controllers { private readonly ITenantService _tenantService; - private readonly IFileService _fileService; - - public TenantController(ITenantService tenantService, IFileService fileService) + public TenantController(ITenantService tenantService) { _tenantService = tenantService; - _fileService = fileService; } [Authorize(Roles = UserTypes.UdelarAdmin)] @@ -106,10 +103,40 @@ namespace Tsi1.Api.Controllers } [Authorize(Roles = UserTypes.UdelarAdmin)] - [HttpGet("CourseList")] - public async Task<IActionResult> CourseList() + [HttpGet("AllCourseStudentQuantity")] + public async Task<IActionResult> AllCourseStudentQuantity() + { + var result = await _tenantService.CourseStudentQuantity(); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.UdelarAdmin)] + [HttpGet("FacultyRegistrations")] + public async Task<IActionResult> FacultyRegistrations() { - var result = await _tenantService.CourseList(); + var result = await _tenantService.FacultyRegistrations(); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.FacultyAdmin)] + [HttpGet("CourseStudentQuantity")] + public async Task<IActionResult> CourseStudentQuantity() + { + var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); + + var result = await _tenantService.CourseStudentQuantity(tenantId); if (result.HasError) { diff --git a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs index eee69b7..f47f131 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/UserController.cs @@ -485,7 +485,7 @@ namespace Tsi1.Api.Controllers [AllowAnonymous] [HttpGet("GetAllRefreshTokens")] - public async Task<IActionResult> GetAllRefreshTokens() + public IActionResult GetAllRefreshTokens() { return Ok(_jwtAuthManager.GetRefreshTokens()); } diff --git a/Tsi1.Api/Tsi1.Api/SignalR/VideoHub.cs b/Tsi1.Api/Tsi1.Api/SignalR/VideoHub.cs index 5e62112..f0c0eee 100644 --- a/Tsi1.Api/Tsi1.Api/SignalR/VideoHub.cs +++ b/Tsi1.Api/Tsi1.Api/SignalR/VideoHub.cs @@ -28,8 +28,6 @@ namespace Tsi1.Api.SignalR public async Task Join(string roomName, string offer) { - - Console.WriteLine(offer); await Clients.Group(roomName).SendAsync("Join", Context.ConnectionId, offer); await Groups.AddToGroupAsync(Context.ConnectionId, roomName); diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/RegistrationDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/RegistrationDto.cs new file mode 100644 index 0000000..3e6c24f --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/RegistrationDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.BusinessLayer.Dtos +{ + public class RegistrationDto + { + public int Id { get; set; } + + public string Name { get; set; } + + public int StudentQuantity { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/TenantPreviewDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/TenantPreviewDto.cs index 273d9f5..74b8300 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/TenantPreviewDto.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/TenantPreviewDto.cs @@ -9,7 +9,5 @@ namespace Tsi1.BusinessLayer.Dtos public int Id { get; set; } public string Name { get; set; } - - public int StudentQuantity { get; set; } } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs b/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs index d56100c..a72d596 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs @@ -30,7 +30,7 @@ namespace Tsi1.BusinessLayer.Helpers CreateMap<Course, CoursePreviewDto>(); CreateMap<Tenant, TenantPreviewDto>(); CreateMap<Tenant, TenantCreateDto>(); - CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore()); + CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore()); CreateMap<UserType, UserTypeDto>(); CreateMap<File, FileDto>(); CreateMap<SectionItem, SectionItemCreateDto>(); @@ -52,6 +52,8 @@ namespace Tsi1.BusinessLayer.Helpers CreateMap<Communication, CommunicationCreateDto>(); CreateMap<Communication, CommunicationPreviewDto>(); CreateMap<AnswerOption, AnswerOptionDetailDto>(); + CreateMap<Tenant, RegistrationDto>(); + CreateMap<Course, RegistrationDto>(); CreateMap<ForumCreateDto, Forum>(); CreateMap<ForumPreviewDto, Forum>(); @@ -93,6 +95,8 @@ namespace Tsi1.BusinessLayer.Helpers CreateMap<CommunicationCreateDto, Communication>(); CreateMap<CommunicationPreviewDto, Communication>(); CreateMap<AnswerOptionDetailDto, AnswerOption>(); + CreateMap<RegistrationDto, Tenant>(); + CreateMap<RegistrationDto, Course>(); } } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ITenantService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ITenantService.cs index b97247f..fb19c6e 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ITenantService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ITenantService.cs @@ -23,6 +23,10 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<List<TenantPreviewDto>>> FacultyList(); - Task<ServiceResult<List<TenantCourseDto>>> CourseList(); + Task<ServiceResult<List<TenantCourseDto>>> CourseStudentQuantity(); + + Task<ServiceResult<List<RegistrationDto>>> FacultyRegistrations(); + + Task<ServiceResult<List<RegistrationDto>>> CourseStudentQuantity(int tenantId); } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/TenantService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/TenantService.cs index 4b256db..e38b78b 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/TenantService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/TenantService.cs @@ -123,19 +123,19 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<List<TenantPreviewDto>>> FacultyList() + public async Task<ServiceResult<List<RegistrationDto>>> FacultyRegistrations() { - var result = new ServiceResult<List<TenantPreviewDto>>(); + var result = new ServiceResult<List<RegistrationDto>>(); var tenants = await _context.Tenants .Include(x => x.Students) .Where(x => x.Name != TenantAdmin.Name) .ToListAsync(); - var tenantDtos = new List<TenantPreviewDto>(); + var tenantDtos = new List<RegistrationDto>(); foreach (var tenant in tenants) { - var tenantDto = _mapper.Map<TenantPreviewDto>(tenant); + var tenantDto = _mapper.Map<RegistrationDto>(tenant); tenantDto.StudentQuantity = tenant.Students.Count(); tenantDtos.Add(tenantDto); @@ -145,7 +145,20 @@ namespace Tsi1.BusinessLayer.Services return result; } - public async Task<ServiceResult<List<TenantCourseDto>>> CourseList() + public async Task<ServiceResult<List<TenantPreviewDto>>> FacultyList() + { + var result = new ServiceResult<List<TenantPreviewDto>>(); + + var tenants = await _context.Tenants + .Include(x => x.Students) + .Where(x => x.Name != TenantAdmin.Name) + .ToListAsync(); + + result.Data = _mapper.Map<List<TenantPreviewDto>>(tenants); + return result; + } + + public async Task<ServiceResult<List<TenantCourseDto>>> CourseStudentQuantity() { var result = new ServiceResult<List<TenantCourseDto>>(); @@ -193,5 +206,37 @@ namespace Tsi1.BusinessLayer.Services return result; } + + public async Task<ServiceResult<List<RegistrationDto>>> CourseStudentQuantity(int tenantId) + { + var result = new ServiceResult<List<RegistrationDto>>(); + + var tenant = await _context.Tenants.FirstOrDefaultAsync(x => x.Id == tenantId && x.Name != TenantAdmin.Name); + + if (tenant == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.TenantDoesNotExist, tenantId)); + return result; + } + + var courses = await _context.Courses + .Include(x => x.StudentCourses) + .Where(x => x.TenantId == tenantId && !x.IsTemplate) + .ToListAsync(); + + var courseDtos = new List<RegistrationDto>(); + foreach (var course in courses) + { + var courseDto = _mapper.Map<RegistrationDto>(course); + courseDto.StudentQuantity = course.StudentCourses.Count(); + + courseDtos.Add(courseDto); + } + + result.Data = courseDtos; + + return result; + } } } -- GitLab