From 2ec1bc76a41d4ef09013ef53b2205c0d29a6cb9f Mon Sep 17 00:00:00 2001 From: kekentin Date: Wed, 19 Mar 2025 12:00:52 +0100 Subject: [PATCH] Avancement Service Quote --- WF_EF_Api/StubApi/QuoteService.cs | 12 ++--- .../WfApi/Controllers/QuotesController.cs | 45 ++++++++++++++++++- WF_EF_Api/WfApi/WfApi.csproj | 1 + 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/WF_EF_Api/StubApi/QuoteService.cs b/WF_EF_Api/StubApi/QuoteService.cs index d45e6b6..e05f3ae 100644 --- a/WF_EF_Api/StubApi/QuoteService.cs +++ b/WF_EF_Api/StubApi/QuoteService.cs @@ -39,22 +39,22 @@ namespace StubApi }; } - public async Task AddQuote(QuoteDTO quote) + public async Task AddQuote(QuoteDTO quote) { - throw new NotImplementedException(); + _quotes.Add(quote); } public async Task CountQuotes() { - throw new NotImplementedException(); + return _quotes.Count; } public async Task> GetAllQuote() { - throw new NotImplementedException(); + return new PaginationResult(_quotes.Count, 0, _quotes.Count, _quotes); } - public async Task> GetAllQuoteLang(int index, int pageSize, int lang) + public async Task> GetAllQuoteLang(int index, int pageSize, TypeLangageDTO lang) { //TypeLangageDTO langageType = lang; //var listQuote = _quotes.Find(q => q.Langage == langageType); @@ -105,7 +105,7 @@ namespace StubApi public async Task RemoveQuote(int quoteId) { - throw new NotImplementedException(); + _quotes.Remove( GetQuoteById(quoteId).Result ); } public async Task> SearchByCharacter(string character, int index, int pageSize, int lang) diff --git a/WF_EF_Api/WfApi/Controllers/QuotesController.cs b/WF_EF_Api/WfApi/Controllers/QuotesController.cs index 0a50e01..f5cd6ef 100644 --- a/WF_EF_Api/WfApi/Controllers/QuotesController.cs +++ b/WF_EF_Api/WfApi/Controllers/QuotesController.cs @@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Shared; +using System; using System.Net; namespace WfApi.Controllers @@ -23,7 +24,7 @@ namespace WfApi.Controllers //===================================== ROUTE GET ===================================== - [HttpGet("id/{id}")] // Indiquer que l'id est dans l'URL + [HttpGet("{id}")] // Indiquer que l'id est dans l'URL public async Task GetQuote(int id) { try @@ -67,5 +68,47 @@ namespace WfApi.Controllers 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" }); + } + } } } diff --git a/WF_EF_Api/WfApi/WfApi.csproj b/WF_EF_Api/WfApi/WfApi.csproj index a68150a..ab7442c 100644 --- a/WF_EF_Api/WfApi/WfApi.csproj +++ b/WF_EF_Api/WfApi/WfApi.csproj @@ -17,6 +17,7 @@ +