using DTO; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared; using System; using System.Net; namespace WfApi.Controllers { [ApiController] [Route("api/v1/quote")] //Version API public class QuotesController : ControllerBase { private readonly IQuoteService _quote; private readonly ILogger _logger; public QuotesController(IQuoteService quoteService, ILogger logger) { _quote = quoteService; _logger = logger; } //===================================== ROUTE GET ===================================== [HttpGet("{id}")] // Indiquer que l'id est dans l'URL public async Task GetQuote(int id) { try { var result = _quote.GetQuoteById(id); if (result.IsCompletedSuccessfully) { return await Task.FromResult(Ok(result)); } else { return NoContent(); } } catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } [HttpGet("all")] // Indiquer que l'id est dans l'URL public async Task GetAllQuote(int index = 0, int count = 10) { try { var result = _quote.GetSomeQuote(index, count); if (result.IsCompletedSuccessfully) { return await Task.FromResult(Ok(result)); } else { return NoContent(); } } catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } [HttpGet("allbylang")] // Indiquer que l'id est dans l'URL public async Task GetAllQuoteByLang(TypeLangageDTO lang,int index = 0, int count = 10) { try { var result = _quote.GetAllQuoteLang(index, count,(int)lang); if (result.IsCompletedSuccessfully) { return await Task.FromResult(Ok(result)); } else { return NoContent(); } } catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } [HttpDelete("delete")] public async Task DeleteQuote([FromQuery] int idQuote) { try { var result = _quote.RemoveQuote(idQuote); if (result.IsCompletedSuccessfully) { return await Task.FromResult(Ok(result)); } else { return NotFound(); } } catch (Exception) { return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); } } } }