From 7cd0663e1226b2afacac52b7de0cc70d8e90e3ba Mon Sep 17 00:00:00 2001 From: esantangelo <enzo020895@gmail.com> Date: Mon, 7 Dec 2020 21:14:10 -0300 Subject: [PATCH] api --- .../Controllers/ActivityController.cs | 59 -------- .../Controllers/EvaluationController.cs | 138 ++++++++++++++++++ Tsi1.Api/Tsi1.Api/Startup.cs | 1 + 3 files changed, 139 insertions(+), 59 deletions(-) create mode 100644 Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs diff --git a/Tsi1.Api/Tsi1.Api/Controllers/ActivityController.cs b/Tsi1.Api/Tsi1.Api/Controllers/ActivityController.cs index 6987480..4dd5d23 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/ActivityController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/ActivityController.cs @@ -81,64 +81,5 @@ namespace Tsi1.Api.Controllers return Ok(); } - [Authorize(Roles = UserTypes.Professor)] - [HttpPut("AddOrModifyGrade")] - public async Task<IActionResult> AddOrModifyGrade(GradeDto gradeDto) - { - var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); - var result = await _activityService.AddOrModifyGrade(gradeDto, userId); - - if (result.HasError) - { - return BadRequest(result.Message); - } - - return Ok(result.Data); - } - - [Authorize(Roles = UserTypes.Professor)] - [HttpDelete("DeleteGrade/{activityId}/{userId}")] - public async Task<IActionResult> DeleteGrade(int activityId, int userId) - { - var myUserId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); - var result = await _activityService.DeleteGrade(myUserId, activityId, userId); - - if (result.HasError) - { - return BadRequest(result.Message); - } - - return Ok(); - } - - [Authorize(Roles = UserTypes.Student)] - [HttpGet("GetMyGrades/{activityId}")] - public async Task<IActionResult> GetMyGrades(int activityId) - { - var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); - var result = await _activityService.GetMyGrades(activityId, userId); - - if (result.HasError) - { - return BadRequest(result.Message); - } - - return Ok(result.Data); - } - - [Authorize(Roles = UserTypes.Professor + ", " + UserTypes.FacultyAdmin)] - [HttpGet("GetAllGrades/{activityId}")] - public async Task<IActionResult> GetAllGrades(int activityId) - { - var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); - var result = await _activityService.GetAllGrades(activityId, userId); - - if (result.HasError) - { - return BadRequest(result.Message); - } - - return Ok(result.Data); - } } } diff --git a/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs new file mode 100644 index 0000000..669c0e2 --- /dev/null +++ b/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs @@ -0,0 +1,138 @@ +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Tsi1.BusinessLayer.Dtos; +using Tsi1.BusinessLayer.Helpers; +using Tsi1.BusinessLayer.Interfaces; + +namespace Tsi1.Api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class EvaluationController : ControllerBase + { + private readonly IEvaluationService _evaluationService; + + public EvaluationController(IEvaluationService evaluationService) + { + _evaluationService = evaluationService; + } + + [Authorize(Roles = UserTypes.Student)] + [HttpPost("Registration/{evaluationId}")] + public async Task<IActionResult> GetAll(int evaluationId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.Registration(evaluationId, userId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.Student)] + [HttpPost("CancelRegistration/{evaluationId}")] + public async Task<IActionResult> CancelRegistration(int evaluationId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.CancelRegistration(evaluationId, userId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.Student)] + [HttpPost("SubmitLaboratory/{evaluationId}")] + public async Task<IActionResult> SubmitLaboratory(FileDto fileDto, int evaluationId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.SubmitLaboratory(fileDto, evaluationId, userId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.Student)] + [HttpDelete("DeleteLaboratory/{submissionId}")] + public async Task<IActionResult> DeleteLaboratory(int submissionId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.DeleteLaboratory(submissionId, userId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.Student)] + [HttpGet("GetMyEvaluationInscriptions/{courseId}")] + public async Task<IActionResult> GetMyEvaluationInscriptions(int courseId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.GetMyEvaluationInscriptions(userId, courseId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + [Authorize(Roles = UserTypes.Professor)] + [HttpGet("GetAllEvaluationInscriptions/{evaluationId}")] + public async Task<IActionResult> GetAllEvaluationInscriptions(int evaluationId) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.GetAllEvaluationInscriptions(userId, evaluationId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + + //QualifyEvaluationInscription(EvaluationInscriptionModifyDto evaluationInscriptionDto, int userId); + [Authorize(Roles = UserTypes.Professor)] + [HttpPost("QualifyEvaluationInscription")] + public async Task<IActionResult> SubmitLaboratory(EvaluationInscriptionModifyDto evaluationInscriptionDto) + { + var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); + + var result = await _evaluationService.QualifyEvaluationInscription(evaluationInscriptionDto, userId); + + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + } +} diff --git a/Tsi1.Api/Tsi1.Api/Startup.cs b/Tsi1.Api/Tsi1.Api/Startup.cs index 5718b4a..1f237ec 100644 --- a/Tsi1.Api/Tsi1.Api/Startup.cs +++ b/Tsi1.Api/Tsi1.Api/Startup.cs @@ -106,6 +106,7 @@ namespace Tsi1.Api services.AddScoped<ICommunicationService, CommunicationService>(); services.AddScoped<IChatService, ChatService>(); services.AddScoped<IActivityService, ActivityService>(); + services.AddScoped<IEvaluationService, EvaluationService>(); services.AddSingleton<PresenceTracker>(); -- GitLab