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.
72 lines
2.1 KiB
72 lines
2.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/{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")] // Indiquer que l'id est dans l'URL
|
|
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" });
|
|
}
|
|
}
|
|
}
|
|
}
|