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.
160 lines
5.1 KiB
160 lines
5.1 KiB
using DTO;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Shared;
|
|
using System.Net;
|
|
|
|
namespace WfApi.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/v1/quote")] //Version API
|
|
public class QuotesController : ControllerBase
|
|
{
|
|
private readonly IQuoteService<QuoteDTO> _quote;
|
|
|
|
private readonly ILogger<UsersController> _logger;
|
|
public QuotesController(IQuoteService<QuoteDTO> quoteService, ILogger<UsersController> logger)
|
|
{
|
|
_quote = quoteService;
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================== ROUTE GET =====================================
|
|
[HttpGet("{id}")] // Indiquer que l'id est dans l'URL
|
|
public async Task<IActionResult> GetQuote(int id)
|
|
{
|
|
try
|
|
{
|
|
var result = _quote.GetQuoteById(id);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet("all")]
|
|
public async Task<IActionResult> GetAllQuote(int index = 0, int count = 10)
|
|
{
|
|
try
|
|
{
|
|
var result = _quote.GetSomeQuote(index, count);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
[HttpGet("allbylang")]
|
|
public async Task<IActionResult> 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<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
[HttpGet("dailyquote")]
|
|
public async Task<IActionResult> GetDailyQuote([FromQuery] int year, [FromQuery] int month, [FromQuery] int day, TypeLangageDTO lang)
|
|
{
|
|
try
|
|
{
|
|
DateOnly date = new DateOnly(year, month, day);
|
|
|
|
var result = _quote.GetDailyQuote(date, (int)lang);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
[HttpGet("invalid")]
|
|
public async Task<IActionResult> GetInvalidQuote(TypeLangageDTO lang, int index = 0, int count = 10)
|
|
{
|
|
try
|
|
{
|
|
var result = _quote.GetInvalidQuote(index, count, (int)lang);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NoContent();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
|
|
//===================================== ROUTE DELETE =====================================
|
|
[HttpDelete("delete")]
|
|
public async Task<IActionResult> DeleteQuote([FromQuery] int idQuote)
|
|
{
|
|
try
|
|
{
|
|
var result = _quote.RemoveQuote(idQuote);
|
|
|
|
if (result.IsCompletedSuccessfully)
|
|
{
|
|
return await Task.FromResult<IActionResult>(Ok(result));
|
|
}
|
|
else
|
|
{
|
|
return NotFound();
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
|
|
}
|
|
}
|
|
}
|
|
}
|