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.
49 lines
1.2 KiB
49 lines
1.2 KiB
using Dto.Classe;
|
|
using Dto.Factories;
|
|
using Interface;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Modele.Classe;
|
|
|
|
namespace Api.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class Circuits : Controller
|
|
{
|
|
private readonly IApi data;
|
|
|
|
public Circuits(IApi manager)
|
|
{
|
|
this.data = manager;
|
|
}
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get(string name = "All")
|
|
{
|
|
if (name == "All")
|
|
{
|
|
return Ok((await data.GetCircuits()).Select(e => e.ModeleToDTO()));
|
|
}
|
|
|
|
Circuit circuit = await data.GetOneCircuit(name);
|
|
if (circuit == null)
|
|
{
|
|
return BadRequest(name);
|
|
}
|
|
return Ok(circuit.ModeleToDTO());
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<IActionResult> Post(CircuitDTO circuitDto)
|
|
{
|
|
Circuit circuit = await data.AddCircuit(circuitDto.DTOToModele());
|
|
|
|
if (circuit == null)
|
|
{
|
|
return BadRequest("Le pilote existe déjà !");
|
|
}
|
|
return Ok(circuit.ModeleToDTO());
|
|
}
|
|
}
|
|
}
|