You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.3 KiB
86 lines
3.3 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using Server.Dto.Request;
|
|
using Server.Dto.Response;
|
|
using Asp.Versioning;
|
|
using Server.IServices;
|
|
using Shared.Criteria;
|
|
|
|
namespace Server.Controller.v1;
|
|
|
|
[ApiController]
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]")]
|
|
public class FormationsController : ControllerBase
|
|
{
|
|
private readonly ILogger<FormationsController> _logger;
|
|
private IFormationsService _dataServices;
|
|
|
|
public FormationsController(ILogger<FormationsController> logger, IFormationsService dataServices)
|
|
{
|
|
_logger = logger;
|
|
_dataServices = dataServices;
|
|
}
|
|
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(IEnumerable<ResponseFormationDto>), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
[RequireHttps]
|
|
public async Task<IActionResult> GetFormations([FromQuery] string? name, [FromQuery] int page = 1, [FromQuery] int size = 5,
|
|
[FromQuery] FormationOrderCriteria criteria = FormationOrderCriteria.StartDate, [FromQuery] bool ascending = true)
|
|
{
|
|
var result = await _dataServices.GetFormations(name, page, size, criteria, ascending);
|
|
if (result.Count == 0) return NoContent();
|
|
return Ok(result.Formations);
|
|
}
|
|
|
|
[HttpGet("{id}")]
|
|
[ProducesResponseType(typeof(ResponseFormationDto), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[RequireHttps]
|
|
public IActionResult GetFormationById(string id)
|
|
{
|
|
var formation = _dataServices.GetFormationById(id);
|
|
return formation.Result == null ? NotFound() : Ok(formation.Result);
|
|
}
|
|
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(ResponseFormationDto), StatusCodes.Status201Created)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[RequireHttps]
|
|
public IActionResult CreateFormation([FromBody] RequestFormationDto experienceDto)
|
|
{
|
|
var formation = _dataServices.CreateFormation(experienceDto);
|
|
return formation.Result == null ? BadRequest() : CreatedAtAction(nameof(CreateFormation), formation.Result);
|
|
}
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
[ProducesResponseType(typeof(ResponseFormationDto), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
[RequireHttps]
|
|
public IActionResult UpdateFormation(string id, [FromBody] RequestFormationDto formation)
|
|
{
|
|
var formationSelected = _dataServices.UpdateFormation(id, formation);
|
|
return formationSelected.Result == null ? BadRequest() : Ok(formationSelected.Result);
|
|
}
|
|
|
|
[HttpDelete("{id}")]
|
|
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
[RequireHttps]
|
|
public IActionResult DeleteFormation(string id)
|
|
{
|
|
return _dataServices.DeleteFormation(id).Result ? Ok() : NotFound();
|
|
}
|
|
|
|
[HttpGet("Alica/{id}")]
|
|
[ProducesResponseType(typeof(IEnumerable<ResponseFormationDto>), StatusCodes.Status200OK)]
|
|
[RequireHttps]
|
|
public IActionResult GetFormationsByAlumniId(string id)
|
|
{
|
|
//var formation = _dataServices.GetData();
|
|
//var formationSelected = formation.Result.Where(x => x.AlicaId == id).ToList();
|
|
//return formationSelected.Count() == 0 ? NoContent() : Ok(formationSelected);
|
|
return Ok();
|
|
}
|
|
} |