|
|
|
@ -3,18 +3,29 @@ using WF_WebAdmin.Model;
|
|
|
|
|
|
|
|
|
|
namespace WF_WebAdmin.Service;
|
|
|
|
|
|
|
|
|
|
public class QuoteServiceStub : IQuoteService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Service de gestion des citations utilisant un fichier JSON comme stockage.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class QuoteServiceStub : IQuoteService
|
|
|
|
|
{
|
|
|
|
|
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataQuote.json");
|
|
|
|
|
private readonly string _char = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataCaracter.json");
|
|
|
|
|
private readonly string _src = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataSource.json");
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sauvegarde la liste des citations dans le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quotes">Liste des citations à sauvegarder.</param>
|
|
|
|
|
public async Task saveQuoteJson(List<Quote> quotes)
|
|
|
|
|
{
|
|
|
|
|
var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
|
await File.WriteAllTextAsync(_jsonFilePath, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ajoute une nouvelle citation et l'enregistre dans le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">Citation à ajouter.</param>
|
|
|
|
|
public async Task addQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
@ -23,6 +34,10 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Supprime une citation et met à jour le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">Citation à supprimer.</param>
|
|
|
|
|
public async Task removeQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
@ -34,11 +49,19 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Marque une citation comme valide.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">Citation à valider.</param>
|
|
|
|
|
public async Task validQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Met à jour une citation existante.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="quote">Citation mise à jour.</param>
|
|
|
|
|
public async Task updateQuote(Quote quote)
|
|
|
|
|
{
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
@ -55,6 +78,10 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère toutes les citations stockées dans le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Une liste de citations.</returns>
|
|
|
|
|
public async Task<List<Quote>> getAllQuote()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(_jsonFilePath))
|
|
|
|
@ -67,36 +94,53 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
return JsonSerializer.Deserialize<List<Quote>>(json) ?? new List<Quote>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère une liste paginée de citations.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="nb">Nombre de citations par page.</param>
|
|
|
|
|
/// <param name="page">Numéro de la page.</param>
|
|
|
|
|
/// <returns>Une liste de citations correspondant à la page demandée.</returns>
|
|
|
|
|
public async Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
var quotes = await getAllQuote();
|
|
|
|
|
if((page - 1) * nb + nb > quotes.Count())
|
|
|
|
|
if ((page - 1) * nb + nb > quotes.Count())
|
|
|
|
|
{
|
|
|
|
|
if (nb > quotes.Count())
|
|
|
|
|
{
|
|
|
|
|
return quotes.GetRange(0, quotes.Count());
|
|
|
|
|
}
|
|
|
|
|
return quotes.GetRange(quotes.Count()-nb, nb);
|
|
|
|
|
return quotes.GetRange(quotes.Count() - nb, nb);
|
|
|
|
|
}
|
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère une citation spécifique en fonction de son ID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">ID de la citation recherchée.</param>
|
|
|
|
|
/// <returns>La citation correspondante ou null si elle n'existe pas.</returns>
|
|
|
|
|
public async Task<Quote> getOnequote(int id)
|
|
|
|
|
{
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == id);
|
|
|
|
|
if (q != null)
|
|
|
|
|
{
|
|
|
|
|
return q;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Recherche des citations selon des critères spécifiques.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="reserch">Terme de recherche.</param>
|
|
|
|
|
/// <param name="argument">Liste d'arguments pour affiner la recherche.</param>
|
|
|
|
|
/// <returns>Une liste de citations correspondant aux critères de recherche.</returns>
|
|
|
|
|
public async Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère toutes les citations invalides.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Une liste de citations non validées.</returns>
|
|
|
|
|
public async Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
|
{
|
|
|
|
|
var quotes = await getAllQuote();
|
|
|
|
@ -104,6 +148,12 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
return quotes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère une liste paginée de citations invalides.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="nb">Nombre de citations par page.</param>
|
|
|
|
|
/// <param name="page">Numéro de la page.</param>
|
|
|
|
|
/// <returns>Une liste de citations non validées correspondant à la page demandée.</returns>
|
|
|
|
|
public async Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
|
{
|
|
|
|
|
var quotes = await getAllQuoteInvalid();
|
|
|
|
@ -118,12 +168,20 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère le nombre total de citations enregistrées.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Nombre total de citations.</returns>
|
|
|
|
|
public async Task<int> getNbQuote()
|
|
|
|
|
{
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
|
return data.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère la liste des personnages depuis le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Une liste de personnages.</returns>
|
|
|
|
|
public async Task<List<Character>> getChar()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(_char))
|
|
|
|
@ -136,6 +194,10 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
return JsonSerializer.Deserialize<List<Character>>(json) ?? new List<Character>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Récupère la liste des sources depuis le fichier JSON.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Une liste de sources.</returns>
|
|
|
|
|
public async Task<List<Source>> getSrc()
|
|
|
|
|
{
|
|
|
|
|
if (!File.Exists(_src))
|
|
|
|
@ -148,4 +210,3 @@ namespace WF_WebAdmin.Service;
|
|
|
|
|
return JsonSerializer.Deserialize<List<Source>>(json) ?? new List<Source>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|