Création de nouvelle route pour l'API

API_init
kekentin 1 month ago
parent 2c2e09704d
commit ec34797b76

@ -17,5 +17,6 @@ namespace DTO
public int Like { get; set; }
public TypeLangageDTO Langage { get; set; }
public TypeSrcEnumDTO Type { get; set; }
public Boolean IsValide { get; set; }
}
}

@ -10,7 +10,7 @@ namespace Shared
{
// Retrieves the daily quote in a specified language.
// 'lang' is a language code.
Task<TQuote> GetDayliQuote(int lang);
Task<TQuote> GetDailyQuote(DateOnly date, int lang);
// Retrieves a specific quote by its unique identifier (id).
Task<TQuote> GetQuoteById(int id);
@ -27,6 +27,9 @@ namespace Shared
// 'lang' is a language code used to filter the quotes in the chosen language.
Task<PaginationResult<TQuote>> GetAllQuoteLang(int index, int pageSize, int lang);
// Retrieves all inavailable quotes but filtered by language.
// 'lang' is a language code used to filter the quotes in the chosen language.
Task<PaginationResult<TQuote>> GetInvalidQuote(int index, int pageSize, int lang);
// Retrieves a page of quote suggestions based on the index (pagination) and language.
// 'index' is the starting point for pagination
// 'pageSize' determines the number of quotes per page
@ -83,14 +86,12 @@ namespace Shared
// Removes a quote based on its unique identifier ('quoteId').
Task RemoveQuote(int quoteId);
// Returns the total number of quotes available.
Task<int> CountQuotes();
// Retrieves the last ID.
Task<int> GetLastQuoteId();
// Validates or invalidates a quote based on the 'quoteId' and a boolean value ('isValidate').
// If 'isValidate' is true, the quote is marked as valid; if false, it is invalid.
Task ValidateQuote(int quoteId, bool isValidate);
}
}

@ -16,26 +16,26 @@ namespace StubApi
{
_quotes = new List<QuoteDTO>
{
new QuoteDTO{Id=1, Content="Que la force soit avec toi", Character="Obi-Wan", ImagePath="http://image1", TitleSource="Star Wars", DateSource=1977, Like=32, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=2, Content="Je suis ton père", Character="Darth Vader", ImagePath="http://image2", TitleSource="Star Wars", DateSource=1980, Like=120, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=3, Content="Que la vengeance commence", Character="Anakin Skywalker", ImagePath="http://image3", TitleSource="Star Wars: Episode III", DateSource=2005, Like=95, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=4, Content="J'adore l'odeur du napalm au matin", Character="Kilgore", ImagePath="http://image4", TitleSource="Apocalypse Now", DateSource=1979, Like=56, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=5, Content="Je suis Groot", Character="Groot", ImagePath="http://image5", TitleSource="Guardians of the Galaxy", DateSource=2014, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=6, Content="La vie est un rêve", Character="Don Quichotte", ImagePath="http://image6", TitleSource="Don Quichotte", DateSource=1605, Like=34, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=7, Content="To infinity and beyond!", Character="Buzz Lightyear", ImagePath="http://image7", TitleSource="Toy Story", DateSource=1995, Like=180, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=8, Content="Je ne suis pas un héros", Character="Bruce Wayne", ImagePath="http://image8", TitleSource="The Dark Knight", DateSource=2008, Like=250, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=9, Content="Je suis le maître du jeu", Character="Jigsaw", ImagePath="http://image9", TitleSource="Saw", DateSource=2004, Like=65, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=10, Content="Liberté, égalité, fraternité", Character="La devise de la France", ImagePath="http://image10", TitleSource="Révolution française", DateSource=1789, Like=300, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=11, Content="Un petit pas pour l'homme, un grand pas pour l'humanité", Character="Neil Armstrong", ImagePath="http://image11", TitleSource="Moon landing", DateSource=1969, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=12, Content="C'est la vie", Character="Charles", ImagePath="http://image12", TitleSource="French Movie", DateSource=2013, Like=45, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=13, Content="Voici Johnny!", Character="Jack Torrance", ImagePath="http://image13", TitleSource="The Shining", DateSource=1980, Like=300, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=14, Content="Je suis un simple serveur", Character="Hannibal", ImagePath="http://image14", TitleSource="The Silence of the Lambs", DateSource=1991, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=15, Content="N'attends pas le moment parfait, prends le moment et rends-le parfait", Character="Zig Ziglar", ImagePath="http://image15", TitleSource="Motivation", DateSource=1995, Like=150, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=16, Content="Le seul vrai voyage est de changer de regard", Character="Marcel Proust", ImagePath="http://image16", TitleSource="À la recherche du temps perdu", DateSource=1913, Like=125, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=17, Content="La force sera avec toi, toujours", Character="Obi-Wan Kenobi", ImagePath="http://image17", TitleSource="Star Wars: Episode IV", DateSource=1977, Like=320, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=18, Content="J'ai toujours rêvé d'être un gangster", Character="Henry Hill", ImagePath="http://image18", TitleSource="Goodfellas", DateSource=1990, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie},
new QuoteDTO{Id=19, Content="Je vous ai compris", Character="De Gaulle", ImagePath="http://image19", TitleSource="Discours de Gaulle", DateSource=1958, Like=250, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book},
new QuoteDTO{Id=20, Content="Courage, fuyons!", Character="Frédéric", ImagePath="http://image20", TitleSource="Le Pourceau", DateSource=1834, Like=75, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book}
new QuoteDTO{Id=0, Content="Que la force soit avec toi", Character="Obi-Wan", ImagePath="http://image1", TitleSource="Star Wars", DateSource=1977, Like=32, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=1, Content="Je suis ton père", Character="Darth Vader", ImagePath="http://image2", TitleSource="Star Wars", DateSource=1980, Like=120, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=2, Content="Que la vengeance commence", Character="Anakin Skywalker", ImagePath="http://image3", TitleSource="Star Wars: Episode III", DateSource=2005, Like=95, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=3, Content="J'adore l'odeur du napalm au matin", Character="Kilgore", ImagePath="http://image4", TitleSource="Apocalypse Now", DateSource=1979, Like=56, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=4, Content="Je suis Groot", Character="Groot", ImagePath="http://image5", TitleSource="Guardians of the Galaxy", DateSource=2014, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=5, Content="La vie est un rêve", Character="Don Quichotte", ImagePath="http://image6", TitleSource="Don Quichotte", DateSource=1605, Like=34, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=6, Content="To infinity and beyond!", Character="Buzz Lightyear", ImagePath="http://image7", TitleSource="Toy Story", DateSource=1995, Like=180, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=7, Content="Je ne suis pas un héros", Character="Bruce Wayne", ImagePath="http://image8", TitleSource="The Dark Knight", DateSource=2008, Like=250, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=8, Content="Je suis le maître du jeu", Character="Jigsaw", ImagePath="http://image9", TitleSource="Saw", DateSource=2004, Like=65, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=9, Content="Liberté, égalité, fraternité", Character="La devise de la France", ImagePath="http://image10", TitleSource="Révolution française", DateSource=1789, Like=300, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=10, Content="Un petit pas pour l'homme, un grand pas pour l'humanité", Character="Neil Armstrong", ImagePath="http://image11", TitleSource="Moon landing", DateSource=1969, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=11, Content="C'est la vie", Character="Charles", ImagePath="http://image12", TitleSource="French Movie", DateSource=2013, Like=45, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=12, Content="Voici Johnny!", Character="Jack Torrance", ImagePath="http://image13", TitleSource="The Shining", DateSource=1980, Like=300, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=13, Content="Je suis un simple serveur", Character="Hannibal", ImagePath="http://image14", TitleSource="The Silence of the Lambs", DateSource=1991, Like=200, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=14, Content="N'attends pas le moment parfait, prends le moment et rends-le parfait", Character="Zig Ziglar", ImagePath="http://image15", TitleSource="Motivation", DateSource=1995, Like=150, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=15, Content="Le seul vrai voyage est de changer de regard", Character="Marcel Proust", ImagePath="http://image16", TitleSource="À la recherche du temps perdu", DateSource=1913, Like=125, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=16, Content="La force sera avec toi, toujours", Character="Obi-Wan Kenobi", ImagePath="http://image17", TitleSource="Star Wars: Episode IV", DateSource=1977, Like=320, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=17, Content="J'ai toujours rêvé d'être un gangster", Character="Henry Hill", ImagePath="http://image18", TitleSource="Goodfellas", DateSource=1990, Like=500, Langage=TypeLangageDTO.vo, Type=TypeSrcEnumDTO.movie,IsValide=true},
new QuoteDTO{Id=18, Content="Je vous ai compris", Character="De Gaulle", ImagePath="http://image19", TitleSource="Discours de Gaulle", DateSource=1958, Like=250, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=true},
new QuoteDTO{Id=19, Content="Courage, fuyons!", Character="Frédéric", ImagePath="http://image20", TitleSource="Le Pourceau", DateSource=1834, Like=75, Langage=TypeLangageDTO.vf, Type=TypeSrcEnumDTO.book,IsValide=false}
};
}
@ -44,28 +44,30 @@ namespace StubApi
_quotes.Add(quote);
}
public async Task<int> CountQuotes()
{
return _quotes.Count;
}
public async Task<PaginationResult<QuoteDTO>> GetAllQuote()
{
return new PaginationResult<QuoteDTO>(_quotes.Count, 0, _quotes.Count, _quotes);
return new PaginationResult<QuoteDTO>(_quotes.Where(q=>q.IsValide == true).ToList().Count,
0,
_quotes.Count,
_quotes.Where(q => q.IsValide == true).ToList());
}
public async Task<PaginationResult<QuoteDTO>> GetAllQuoteLang(int index, int pageSize, TypeLangageDTO lang)
public async Task<PaginationResult<QuoteDTO>> GetAllQuoteLang(int index, int pageSize, int lang)
{
//TypeLangageDTO langageType = lang;
//var listQuote = _quotes.Find(q => q.Langage == langageType);
//return new PaginationResult<QuoteDTO>(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList());
throw new NotImplementedException();
TypeLangageDTO langageType = (TypeLangageDTO)lang;
return new PaginationResult<QuoteDTO>(_quotes.Where(q => q.IsValide = true).ToList().Count,
index,
pageSize,
_quotes.Where(q => q.IsValide == true && q.Langage == langageType ).ToList().Skip(index * pageSize).Take(pageSize).ToList()
);
}
public async Task<QuoteDTO> GetDayliQuote(int lang)
public async Task<QuoteDTO> GetDailyQuote(DateOnly date, int lang)
{
throw new NotImplementedException();
int nb = _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).Count();
return _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).ToList().Find(q => q.Id == date.DayNumber%nb) ?? _quotes.Where(q => q.Langage == (TypeLangageDTO)lang && q.IsValide == true).First();
}
public async Task<PaginationResult<QuoteDTO>> GetFavorites(int index, int pageSize, int UserId)
@ -90,7 +92,11 @@ namespace StubApi
public async Task<PaginationResult<QuoteDTO>> GetSomeQuote(int index, int pageSize)
{
return new PaginationResult<QuoteDTO>(_quotes.Count, index, pageSize, _quotes.Skip(index * pageSize).Take(pageSize).ToList());
return new PaginationResult<QuoteDTO>(_quotes.Where(q => q.IsValide = true).ToList().Count,
index,
pageSize,
_quotes.Where(q => q.IsValide = true).ToList().Skip(index * pageSize).Take(pageSize).ToList()
);
}
public async Task<PaginationResult<QuoteDTO>> GetSuggestions(int index, int pageSize, int lang)
@ -132,5 +138,15 @@ namespace StubApi
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> GetInvalidQuote(int index, int pageSize, int lang)
{
TypeLangageDTO langageType = (TypeLangageDTO)lang;
return new PaginationResult<QuoteDTO>(_quotes.Where(q => q.IsValide == false && q.Langage == langageType).ToList().Count,
index,
pageSize,
_quotes.Where(q => q.IsValide == false && q.Langage == langageType).ToList().Skip(index * pageSize).Take(pageSize).ToList()
);
}
}
}

@ -2,7 +2,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Shared;
using System;
using System.Net;
namespace WfApi.Controllers
@ -47,7 +46,7 @@ namespace WfApi.Controllers
}
[HttpGet("all")] // Indiquer que l'id est dans l'URL
[HttpGet("all")]
public async Task<IActionResult> GetAllQuote(int index = 0, int count = 10)
{
try
@ -68,7 +67,7 @@ namespace WfApi.Controllers
return StatusCode((int)HttpStatusCode.InternalServerError, new { message = "Internal Server Error" });
}
}
[HttpGet("allbylang")] // Indiquer que l'id est dans l'URL
[HttpGet("allbylang")]
public async Task<IActionResult> GetAllQuoteByLang(TypeLangageDTO lang,int index = 0, int count = 10)
{
try
@ -89,6 +88,52 @@ namespace WfApi.Controllers
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)
{

@ -1,13 +0,0 @@
namespace WfApi
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}
Loading…
Cancel
Save