Controller de quote

pull/4/head
lebeaulato 3 months ago
parent fdcf26413c
commit 6eaa80172b

@ -13,9 +13,9 @@ namespace DTO
public string Character { get; set; }
public string ImagePath { get; set; }
public string TitleSource { get; set; }
public DateTime DateSource { get; set; }
public int DateSource { get; set; }
public int Like { get; set; }
public string Langage { get; set; }
public TypeLangageDTO Langage { get; set; }
public TypeSrcEnumDTO Type { get; set; }
}
}

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public enum TypeLangageDTO
{
vo,
vf,
ve
}
}

@ -25,7 +25,7 @@ namespace Shared
// Retrieves all available quotes but filtered by language.
// 'lang' is a language code used to filter the quotes in the chosen language.
Task<PaginationResult<TQuote>> GetAllQuoteLang(int lang);
Task<PaginationResult<TQuote>> GetAllQuoteLang(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

@ -0,0 +1,136 @@
using DTO;
using Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StubApi
{
public class QuoteService : IQuoteService<QuoteDTO>
{
private readonly List<QuoteDTO> _quotes;
public QuoteService()
{
_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}
};
}
public async Task AddQuote(QuoteDTO quote)
{
throw new NotImplementedException();
}
public async Task<int> CountQuotes()
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> GetAllQuote()
{
throw new NotImplementedException();
}
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();
}
public async Task<QuoteDTO> GetDayliQuote(int lang)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> GetFavorites(int index, int pageSize, int UserId)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> GetInvalidQuote(int index, int pageSize)
{
throw new NotImplementedException();
}
public async Task<int> GetLastQuoteId() // JE VOIS PAS L'INTERET
{
throw new NotImplementedException();
}
public async Task<QuoteDTO> GetQuoteById(int id)
{
return _quotes.FirstOrDefault(q => q.Id == id);
}
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());
}
public async Task<PaginationResult<QuoteDTO>> GetSuggestions(int index, int pageSize, int lang)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> GetValidQuote(int index, int pageSize)
{
throw new NotImplementedException();
}
public async Task RemoveQuote(int quoteId)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> SearchByCharacter(string character, int index, int pageSize, int lang)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> SearchByContent(string content, int index, int pageSize, int lang)
{
throw new NotImplementedException();
}
public async Task<PaginationResult<QuoteDTO>> SearchBySource(string source, int index, int pageSize, int lang)
{
throw new NotImplementedException();
}
public async Task UpdateQuote(int quoteId, QuoteDTO quote)
{
throw new NotImplementedException();
}
public async Task ValidateQuote(int quoteId, bool isValidate)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,71 @@
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" });
}
}
}
}

@ -5,6 +5,7 @@ using StubApi;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IUserService<UserDTO>, UserService>();
builder.Services.AddScoped<IQuoteService<QuoteDTO>, QuoteService>();
// Add services to the container.
builder.Services.AddControllers();
@ -14,7 +15,7 @@ builder.Services.AddOpenApiDocument(options => {
document.Info = new NSwag.OpenApiInfo
{
Version = "v1",
Title = "WtfAPI",
Title = "What The Fantasy's API",
Description = "What The Fantasy Site API",
TermsOfService = "",
Contact = new NSwag.OpenApiContact

Loading…
Cancel
Save