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

merge from develop

parents c08610b9 88d84146
No related branches found
No related tags found
2 merge requests!26Develop,!24Course template
Showing
with 355 additions and 20 deletions
......@@ -21,12 +21,9 @@ namespace Tsi1.Api.Controllers
{
private readonly ICourseService _courseService;
private readonly IFileService _fileService;
public CourseController(ICourseService courseService, IFileService fileService)
public CourseController(ICourseService courseService)
{
_courseService = courseService;
_fileService = fileService;
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
......
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
......@@ -25,7 +26,9 @@ namespace Tsi1.Api.Controllers
[HttpPost("Create")]
public async Task<IActionResult> Create(SectionItemCreateDto sectionItem)
{
var result = await _sectionItemService.Create(sectionItem);
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _sectionItemService.Create(sectionItem, tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Tsi1.BusinessLayer.Dtos;
using Tsi1.BusinessLayer.Helpers;
using Tsi1.BusinessLayer.Interfaces;
using Tsi1.DataLayer.Entities;
namespace Tsi1.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SurveyController : ControllerBase
{
private readonly ISurveyService _surveyService;
public SurveyController(ISurveyService surveyService)
{
_surveyService = surveyService;
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpPost("Create")]
public async Task<IActionResult> Create(SurveyCreateDto newSurvey, int tenantId)
{
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);
}
newSurvey.IsGlobal = true;
var result = await _surveyService.CreateGlobalSurvey(newSurvey, tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok();
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpDelete("Delete/{surveyId}")]
public async Task<IActionResult> Delete(int surveyId)
{
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _surveyService.DeleteGlobalSurvey(surveyId, userType, tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok();
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetAllGlobalSurveys")]
public async Task<IActionResult> GetAllGlobalSurveys(int tenantId)
{
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 result = await _surveyService.GetAllGlobalSurveys(tenantId, userType);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin + ", " + UserTypes.Professor + ", " + UserTypes.Student)]
[HttpGet("GetMySurvey/{surveyId}")]
public async Task<IActionResult> GetMySurvey(int surveyId)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _surveyService.GetMySurvey(surveyId, userId);
if (result.HasError)
{
return NotFound(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student)]
[HttpPost("Complete")]
public async Task<IActionResult> Complete(SurveyResponseCreateDto surveyResponse)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
surveyResponse.UserId = userId;
var result = await _surveyService.Complete(surveyResponse);
if (result.HasError)
{
return NotFound(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin + ", " + UserTypes.Professor)]
[HttpGet("GetAllResponses/{surveyId}")]
public async Task<IActionResult> GetAllResponses(int surveyId)
{
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _surveyService.GetAllResponses(surveyId, userType, tenantId);
if (result.HasError)
{
return NotFound(result.Message);
}
return Ok(result.Data);
}
}
}
......@@ -332,6 +332,22 @@ namespace Tsi1.Api.Controllers
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetAdmins")]
public async Task<IActionResult> GetAdmins()
{
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
var result = await _userService.GetAdmins(tenantId, userType);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
[HttpGet("GetById/{userId}")]
......
......@@ -91,6 +91,7 @@ namespace Tsi1.Api
services.AddScoped<ISectionItemService, SectionItemService>();
services.AddScoped<ISectionItemTypeService, SectionItemTypeService>();
services.AddScoped<IDataLoad, DataLoad>();
services.AddScoped<ISurveyService, SurveyService>();
services.Configure<MailSettings>(Configuration.GetSection("MailSettings"));
services.AddScoped<IEmailService, EmailService>();
......
......@@ -13,29 +13,23 @@ namespace Tsi1.BusinessLayer.DataLoad
public class DataLoad : IDataLoad
{
private readonly Tsi1Context _context;
private readonly IUserTypeService _userTypeService;
private readonly ITenantService _tenantService;
private readonly IUserService _userService;
private readonly ICourseService _courseService;
private readonly ISectionItemTypeService _sectionItemTypeService;
private readonly ISectionService _sectionService;
private readonly ISectionItemService _sectionItemService;
public DataLoad(Tsi1Context context,
IUserTypeService userTypeService,
ITenantService tenantService,
IUserService userService,
ICourseService courseService,
ISectionItemTypeService sectionItemTypeService,
ISectionService sectionService,
ISectionItemService sectionItemService)
{
_context = context;
_userTypeService = userTypeService;
_tenantService = tenantService;
_userService = userService;
_courseService = courseService;
_sectionItemTypeService = sectionItemTypeService;
_sectionService = sectionService;
_sectionItemService = sectionItemService;
}
......@@ -161,6 +155,12 @@ namespace Tsi1.BusinessLayer.DataLoad
};
_context.SectionItemTypes.Add(sectionItemTypeForum);
var sectionItemTypeSurvey = new SectionItemType
{
Name = SectionItemTypes.Survey,
};
_context.SectionItemTypes.Add(sectionItemTypeSurvey);
await _context.SaveChangesAsync();
// COURSES
......@@ -183,7 +183,7 @@ namespace Tsi1.BusinessLayer.DataLoad
Name = "Fisica 1",
TenantId = fingTenantId.Data.Id
};
var course3 = await _courseService.Create(course3Dto);
await _courseService.Create(course3Dto);
// SECTIONS
var section1 = new SectionCreateDto
......@@ -221,7 +221,7 @@ namespace Tsi1.BusinessLayer.DataLoad
Name = "Novedades"
}
};
await _sectionItemService.Create(sectionItem1);
await _sectionItemService.Create(sectionItem1, fingTenantId.Data.Id);
var sectionItem2 = new SectionItemCreateDto
{
......@@ -233,7 +233,7 @@ namespace Tsi1.BusinessLayer.DataLoad
Name = "Novedades"
}
};
await _sectionItemService.Create(sectionItem2);
await _sectionItemService.Create(sectionItem2, fingTenantId.Data.Id);
var sectionItem3 = new SectionItemCreateDto
{
......@@ -245,7 +245,7 @@ namespace Tsi1.BusinessLayer.DataLoad
Name = "General"
}
};
await _sectionItemService.Create(sectionItem3);
await _sectionItemService.Create(sectionItem3, fingTenantId.Data.Id);
var sectionItem4 = new SectionItemCreateDto
{
......@@ -257,7 +257,36 @@ namespace Tsi1.BusinessLayer.DataLoad
Name = "Tema 1"
}
};
await _sectionItemService.Create(sectionItem4);
await _sectionItemService.Create(sectionItem4, fingTenantId.Data.Id);
// ANSWER OPTIONS
var answerOptions = new List<AnswerOption>
{
new AnswerOption
{
Name = "Excelente"
},
new AnswerOption
{
Name = "Conforme"
},
new AnswerOption
{
Name = "Neutro"
},
new AnswerOption
{
Name = "No Conforme"
},
new AnswerOption
{
Name = "Mal"
},
};
_context.AnswerOptions.AddRange(answerOptions);
await _context.SaveChangesAsync();
}
}
}
\ No newline at end of file
......@@ -12,5 +12,7 @@ namespace Tsi1.BusinessLayer.Dtos
public ForumCreateDto Forum { get; set; }
public FileDto File { get; set; }
public SurveyCreateDto Survey { get; set; }
}
}
......@@ -11,5 +11,6 @@ namespace Tsi1.BusinessLayer.Dtos
public int SectionItemTypeId { get; set; }
public ForumPreviewDto Forum { get; set; }
public FileDetailDto File { get; set; }
public SurveyDetailDto Survey { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyAnswerCreateDto
{
public int AnswerOptionId { get; set; }
public int SurveyQuestionId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyAnswerDetailDto
{
public int Id { get; set; }
public int AnswerOptionId { get; set; }
public int SurveyResponseId { get; set; }
public int SurveyQuestionId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyCreateDto
{
public string Name { get; set; }
[JsonIgnore]
public bool IsGlobal { get; set; }
public List<SurveyQuestionCreateDto> SurveyQuestions { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyDetailDto
{
public int Id { get; set; }
public string Name { get; set; }
public bool IsGlobal { get; set; }
public List<SurveyQuestionPreviewDto> SurveyQuestions { get; set; }
public SurveyResponseDetailDto SurveyResponse { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyPreviewDto
{
public int Id { get; set; }
public string Name { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyQuestionCreateDto
{
public string Question { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyQuestionPreviewDto
{
public int Id { get; set; }
public string Question { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyResponseCreateDto
{
[JsonIgnore]
public int UserId { get; set; }
public int SurveyId { get; set; }
public List<SurveyAnswerCreateDto> SurveyAnswers { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class SurveyResponseDetailDto
{
public int Id { get; set; }
public int UserId { get; set; }
public int SurveyId { get; set; }
public List<SurveyAnswerDetailDto> SurveyAnswers { get; set; }
}
}
......@@ -55,5 +55,11 @@ namespace Tsi1.BusinessLayer.Helpers
public const string ForumIsNull = "El foro es nulo";
public const string FileIsNull = "El archivo es nulo";
public const string InvalidSectionItemData = "El tipo de item de seccion '{0}' no coincide con su contenido '{1}'";
public const string SurveyDoesNotExist = "La encuesta con id '{0}' no existe";
public const string SurveyIsNull = "La encuesta es nula";
public const string SurveyHasNoQuestions = "La encuesta no tiene preguntas";
public const string InvalidSurvey = "La encuesta no pertenece a la facultad con id '{0}'";
public const string SurveyResponseAlreadyExist = "El usuario '{0}' ya completo la encuesta '{1}'";
}
}
......@@ -35,13 +35,20 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<File, FileDto>();
CreateMap<SectionItem, SectionItemCreateDto>();
CreateMap<Section, SectionCreateDto>();
CreateMap<SectionItemType, SectionItemTypeDto>();
CreateMap<SectionItemType, SectionItemTypeDto>();
CreateMap<Course, CourseDetailDto>();
CreateMap<Section, SectionDetailDto>();
CreateMap<SectionItem, SectionItemDetailDto>();
CreateMap<File, FileDetailDto>();
CreateMap<Survey, SurveyCreateDto>();
CreateMap<Survey, SurveyPreviewDto>();
CreateMap<Survey, SurveyDetailDto>();
CreateMap<SurveyQuestion, SurveyQuestionCreateDto>();
CreateMap<SurveyQuestion, SurveyQuestionPreviewDto>();
CreateMap<SurveyResponse, SurveyResponseCreateDto>();
CreateMap<SurveyResponse, SurveyResponseDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerCreateDto>();
CreateMap<ForumCreateDto, Forum>();
CreateMap<ForumPreviewDto, Forum>();
......@@ -67,11 +74,20 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<SectionItemCreateDto, SectionItem>();
CreateMap<SectionCreateDto, Section>();
CreateMap<SectionItemTypeDto, SectionItemType>();
CreateMap<CourseDetailDto, Course>();
CreateMap<SectionDetailDto, Section>();
CreateMap<SectionItemDetailDto, SectionItem>();
CreateMap<FileDetailDto, File>();
CreateMap<SurveyCreateDto, Survey>();
CreateMap<SurveyDetailDto, Survey>();
CreateMap<SurveyPreviewDto, Survey>();
CreateMap<SurveyQuestionCreateDto, SurveyQuestion>();
CreateMap<SurveyQuestionPreviewDto, SurveyQuestion>();
CreateMap<SurveyResponseCreateDto, SurveyResponse>();
CreateMap<SurveyResponseDetailDto, SurveyResponse>();
CreateMap<SurveyAnswerDetailDto, SurveyAnswer>();
CreateMap<SurveyAnswerCreateDto, SurveyAnswer>();
CreateMap<Course, Course>().ForMember(x => x.Id, opt => opt.Ignore());
CreateMap<Tenant, Tenant>().ForMember(x => x.Id, opt => opt.Ignore());
......
......@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Helpers
{
public const string Forum = nameof(Forum);
public const string File = nameof(File);
public const string Survey = nameof(Survey);
}
}
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