Skip to content
Snippets Groups Projects
Commit de014506 authored by Lucca Santangelo Dodera's avatar Lucca Santangelo Dodera
Browse files

Merge branch 'feature/udelar-reports' into 'develop'

add 2 endpoints for report

See merge request !14
parents ae28a95d 3063aa25
No related branches found
No related tags found
3 merge requests!20merge from develop,!16Feature/chat signalr,!14add 2 endpoints for report
...@@ -87,5 +87,33 @@ namespace Tsi1.Api.Controllers ...@@ -87,5 +87,33 @@ namespace Tsi1.Api.Controllers
return Ok(); return Ok();
} }
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("FacultyList")]
public async Task<IActionResult> FacultyList()
{
var result = await _tenantService.FacultyList();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("CourseList")]
public async Task<IActionResult> CourseList()
{
var result = await _tenantService.CourseList();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
} }
} }
...@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int StudentQuantity { get; set; }
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class TenantCourseDto
{
public TenantCourseDto()
{
Courses = new List<CoursePreviewDto>();
}
public int Id { get; set; }
public string Name { get; set; }
public List<CoursePreviewDto> Courses { get; set; }
}
}
...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int StudentQuantity { get; set; }
} }
} }
...@@ -29,6 +29,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -29,6 +29,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<Course, CoursePreviewDto>(); CreateMap<Course, CoursePreviewDto>();
CreateMap<Tenant, TenantPreviewDto>(); CreateMap<Tenant, TenantPreviewDto>();
CreateMap<Tenant, TenantCreateDto>(); CreateMap<Tenant, TenantCreateDto>();
CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore());
CreateMap<UserType, UserTypeDto>(); CreateMap<UserType, UserTypeDto>();
CreateMap<ForumCreateDto, Forum>(); CreateMap<ForumCreateDto, Forum>();
...@@ -48,6 +49,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -48,6 +49,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<CoursePreviewDto, Course>(); CreateMap<CoursePreviewDto, Course>();
CreateMap<TenantPreviewDto, Tenant>(); CreateMap<TenantPreviewDto, Tenant>();
CreateMap<TenantCreateDto, Tenant>(); CreateMap<TenantCreateDto, Tenant>();
CreateMap<TenantCourseDto, Tenant>();
CreateMap<UserTypeDto, UserType>(); CreateMap<UserTypeDto, UserType>();
} }
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Helpers
{
public static class TenantAdmin
{
public const string Name = "admin";
}
}
...@@ -18,5 +18,9 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -18,5 +18,9 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<bool>> Modify(int tenantId, TenantCreateDto tenantDto); Task<ServiceResult<bool>> Modify(int tenantId, TenantCreateDto tenantDto);
Task<ServiceResult<bool>> Delete(int tenantId); Task<ServiceResult<bool>> Delete(int tenantId);
Task<ServiceResult<List<TenantPreviewDto>>> FacultyList();
Task<ServiceResult<List<TenantCourseDto>>> CourseList();
} }
} }
using AutoMapper; using AutoMapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Tsi1.BusinessLayer.Dtos; using Tsi1.BusinessLayer.Dtos;
...@@ -122,5 +123,57 @@ namespace Tsi1.BusinessLayer.Services ...@@ -122,5 +123,57 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
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();
var tenantDtos = new List<TenantPreviewDto>();
foreach (var tenant in tenants)
{
var tenantDto = _mapper.Map<TenantPreviewDto>(tenant);
tenantDto.StudentQuantity = tenant.Students.Count();
tenantDtos.Add(tenantDto);
}
result.Data = tenantDtos;
return result;
}
public async Task<ServiceResult<List<TenantCourseDto>>> CourseList()
{
var result = new ServiceResult<List<TenantCourseDto>>();
var tenants = await _context.Tenants
.Include(x => x.Courses)
.ThenInclude(x => x.StudentCourses)
.Where(x => x.Name != TenantAdmin.Name)
.ToListAsync();
var tenantDtos = new List<TenantCourseDto>();
foreach (var tenant in tenants)
{
var tenantDto = _mapper.Map<TenantCourseDto>(tenant);
foreach (var course in tenant.Courses)
{
var courseDto = _mapper.Map<CoursePreviewDto>(course);
courseDto.StudentQuantity = course.StudentCourses.Count();
tenantDto.Courses.Add(courseDto);
}
tenantDtos.Add(tenantDto);
}
result.Data = tenantDtos;
return result;
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment