finition route pour Quote
continuous-integration/drone/push Build is failing Details

pull/6/head
kekentin 3 weeks ago
parent f7f0be36e5
commit 69716c4f9b

@ -1,4 +1,5 @@
using DTO;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared;
@ -132,6 +133,159 @@ namespace WfApi.Controllers
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
[HttpGet("suggest")]
public async Task<IActionResult> GetSuggestQuote(TypeLangageDTO lang, int index = 0, int count = 10)
{
try
{
var result = _quote.GetSuggestions(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("searchByCharacter")]
public async Task<IActionResult> GetQuoteSearchByCharacter(TypeLangageDTO lang, string character, int index = 0, int count = 10)
{
try
{
var result = _quote.SearchByCharacter(character, 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("searchByCharac")]
public async Task<IActionResult> GetQuoteSearchBySource(TypeLangageDTO lang, string source, int index = 0, int count = 10)
{
try
{
var result = _quote.SearchBySource(source, 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("searchByContent")]
public async Task<IActionResult> GetQuoteSearchByContent(TypeLangageDTO lang, string content, int index = 0, int count = 10)
{
try
{
var result = _quote.SearchByContent(content, 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 POST =====================================
[HttpPost]
public async Task<IActionResult> CreateQuote([FromBody] QuoteDTO newQuote)
{
try
{
if (newQuote == null)
{
return BadRequest(new { message = "Les données de la quote sont requises." });
}
var existingPlayer = _quote.GetQuoteById(newQuote.Id).Result;
if (existingPlayer != null)
{
return Conflict(new { message = "Une quote avec cet ID existe déjà." });
}
_quote.AddQuote(newQuote);
return CreatedAtAction(nameof(GetAllQuote), new { id = newQuote.Id }, newQuote);
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Erreur interne du serveur." });
}
}
//===================================== ROUTE PUT =====================================
[HttpPut()]
public async Task<IActionResult> UpdateQuote([FromQuery] int id, [FromBody] QuoteDTO updatedquote)
{
try
{
if (updatedquote == null)
{
return BadRequest(new { message = "Quote data is required." });
}
var result = _quote.UpdateQuote(id, updatedquote);
return Ok(result);
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
}
[HttpPut("valide")]
public async Task<IActionResult> ValideQuote([FromQuery] int id)
{
try
{
var updatedquote = _quote.GetQuoteById(id).Result;
if (updatedquote == null)
{
return BadRequest(new { message = "Id Quote is underfined." });
}
updatedquote.IsValide = true;
var result = _quote.UpdateQuote(id, updatedquote);
return Ok(result);
}
catch (Exception)
{
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal server error." });
}
}
//===================================== ROUTE DELETE =====================================
[HttpDelete("delete")]

Loading…
Cancel
Save