Skip to content
Snippets Groups Projects
Commit 399f38e7 authored by Enzo Santangelo Dodera's avatar Enzo Santangelo Dodera
Browse files

Merge branch 'feature/reports' into 'develop'

reports

See merge request !30
parents 7f8ea9c4 06e1692e
Branches
No related tags found
2 merge requests!31Develop,!30reports
Pipeline #10471 passed
Showing with 133 additions and 35 deletions
......@@ -64,15 +64,11 @@ namespace Tsi1.Api.Controllers
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetAllGlobalSurveys")]
public async Task<IActionResult> GetAllGlobalSurveys(int tenantId)
public async Task<IActionResult> GetAllGlobalSurveys()
{
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
if (userType == UserTypes.FacultyAdmin)
{
tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
}
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _surveyService.GetAllGlobalSurveys(tenantId, userType);
var result = await _surveyService.GetAllGlobalSurveys(tenantId);
if (result.HasError)
{
......
......@@ -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)
{
......
......@@ -485,7 +485,7 @@ namespace Tsi1.Api.Controllers
[AllowAnonymous]
[HttpGet("GetAllRefreshTokens")]
public async Task<IActionResult> GetAllRefreshTokens()
public IActionResult GetAllRefreshTokens()
{
return Ok(_jwtAuthManager.GetRefreshTokens());
}
......
......@@ -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);
......
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; }
}
}
......@@ -9,7 +9,5 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; }
public string Name { get; set; }
public int StudentQuantity { get; set; }
}
}
......@@ -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>();
}
}
}
......@@ -11,7 +11,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
Task<ServiceResult<int>> CreateGlobalSurvey(SurveyCreateDto newSurvey, int tenantId);
Task<ServiceResult<bool>> DeleteGlobalSurvey(int surveyId, string userType, int tenantId);
Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId, string userType);
Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId);
Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId);
Task<ServiceResult<bool>> Complete(SurveyResponseCreateDto surveyResponse);
Task<ServiceResult<List<SurveyResponseDetailDto>>> GetAllResponses(int surveyId, string userType, int tenantId);
......
......@@ -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);
}
}
......@@ -83,24 +83,35 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId, string userType)
public async Task<ServiceResult<List<SurveyPreviewDto>>> GetAllGlobalSurveys(int tenantId)
{
var result = new ServiceResult<List<SurveyPreviewDto>>();
var tenant = await _context.Tenants.FirstOrDefaultAsync(x => x.Id == tenantId);
var tenantAdmin = await _context.Tenants.FirstOrDefaultAsync(x => x.Name == TenantAdmin.Name);
if (tenant == null || userType == UserTypes.UdelarAdmin && tenantAdmin.Id == tenantId)
if (tenant == null)
{
result.HasError = true;
result.AddMessage(string.Format(ErrorMessages.TenantDoesNotExist, tenantId));
return result;
}
var surveys = await _context.Surveys
var surveys = new List<Survey>();
if (tenant.Name == TenantAdmin.Name)
{
surveys = await _context.Surveys
.Include(x => x.Tenant)
.Where(x => x.IsGlobal)
.ToListAsync();
}
else
{
surveys = await _context.Surveys
.Include(x => x.Tenant)
.Where(x => x.IsGlobal && x.Tenant.Id == tenantId)
.ToListAsync();
}
result.Data = _mapper.Map<List<SurveyPreviewDto>>(surveys);
......
......@@ -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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment