Avancement Service Quote

pull/4/head
kekentin 3 months ago
parent 4b4b0495fa
commit 2ec1bc76a4

@ -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<int> CountQuotes() public async Task<int> CountQuotes()
{ {
throw new NotImplementedException(); return _quotes.Count;
} }
public async Task<PaginationResult<QuoteDTO>> GetAllQuote() public async Task<PaginationResult<QuoteDTO>> GetAllQuote()
{ {
throw new NotImplementedException(); return new PaginationResult<QuoteDTO>(_quotes.Count, 0, _quotes.Count, _quotes);
} }
public async Task<PaginationResult<QuoteDTO>> GetAllQuoteLang(int index, int pageSize, int lang) public async Task<PaginationResult<QuoteDTO>> GetAllQuoteLang(int index, int pageSize, TypeLangageDTO lang)
{ {
//TypeLangageDTO langageType = lang; //TypeLangageDTO langageType = lang;
//var listQuote = _quotes.Find(q => q.Langage == langageType); //var listQuote = _quotes.Find(q => q.Langage == langageType);
@ -105,7 +105,7 @@ namespace StubApi
public async Task RemoveQuote(int quoteId) public async Task RemoveQuote(int quoteId)
{ {
throw new NotImplementedException(); _quotes.Remove( GetQuoteById(quoteId).Result );
} }
public async Task<PaginationResult<QuoteDTO>> SearchByCharacter(string character, int index, int pageSize, int lang) public async Task<PaginationResult<QuoteDTO>> SearchByCharacter(string character, int index, int pageSize, int lang)

@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Shared; using Shared;
using System;
using System.Net; using System.Net;
namespace WfApi.Controllers namespace WfApi.Controllers
@ -23,7 +24,7 @@ namespace WfApi.Controllers
//===================================== ROUTE GET ===================================== //===================================== 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<IActionResult> GetQuote(int id) public async Task<IActionResult> GetQuote(int id)
{ {
try try
@ -67,5 +68,47 @@ namespace WfApi.Controllers
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" }); return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
} }
} }
[HttpGet("allbylang")] // Indiquer que l'id est dans l'URL
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" });
}
}
[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" });
}
}
} }
} }

@ -17,6 +17,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Shared\Shared.csproj" /> <ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\StubApi\StubApi.csproj" /> <ProjectReference Include="..\StubApi\StubApi.csproj" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save