Skip to content
Snippets Groups Projects

Feature/results

Merged Enzo Santangelo Dodera requested to merge feature/results into develop
18 files
+ 1762
1
Compare changes
  • Side-by-side
  • Inline
Files
18
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 StudentCourseResultController : ControllerBase
{
private readonly IStudentCourseResultService _studentCourseResultService;
public StudentCourseResultController(IStudentCourseResultService studentCourseResultService)
{
_studentCourseResultService = studentCourseResultService;
}
[Authorize(Roles = UserTypes.Student)]
[HttpGet("GetMyHistoricResults/{courseId}")]
public async Task<IActionResult> GetMyHistoricResults(int courseId)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _studentCourseResultService.GetMyHistoricResults(courseId, userId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student)]
[HttpGet("GetMyLastResult/{courseId}")]
public async Task<IActionResult> GetMyLastResult(int courseId)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _studentCourseResultService.GetMyLastResult(courseId, userId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Professor)]
[HttpGet("GetLastStudentCourseResults/{courseId}")]
public async Task<IActionResult> GetLastStudentCourseResults(int courseId)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _studentCourseResultService.GetLastStudentCourseResults(courseId, userId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.Professor)]
[HttpPost("Create")]
public async Task<IActionResult> Create(StudentCourseResultCreateDto studentCourseResultDto)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _studentCourseResultService.Create(studentCourseResultDto, userId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Professor)]
[HttpDelete("Delete/{studentCourseResultId}")]
public async Task<IActionResult> Delete(int studentCourseResultId)
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var result = await _studentCourseResultService.Delete(studentCourseResultId, userId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok();
}
}
}
Loading