|
|
@ -3,149 +3,210 @@ using WF_WebAdmin.Model;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WF_WebAdmin.Service;
|
|
|
|
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 _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataQuote.json");
|
|
|
|
private readonly string _char = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake-dataCaracter.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");
|
|
|
|
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)
|
|
|
|
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();
|
|
|
|
|
|
|
|
quote.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1;
|
|
|
|
|
|
|
|
data.Add(quote);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == quote.Id);
|
|
|
|
|
|
|
|
if (q != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
data.Remove(q);
|
|
|
|
await File.WriteAllTextAsync(_jsonFilePath, json);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task addQuote(Quote quote)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
|
|
|
|
quote.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1;
|
|
|
|
|
|
|
|
data.Add(quote);
|
|
|
|
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task removeQuote(Quote quote)
|
|
|
|
/// <summary>
|
|
|
|
{
|
|
|
|
/// Marque une citation comme valide.
|
|
|
|
var data = await getAllQuote();
|
|
|
|
/// </summary>
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == quote.Id);
|
|
|
|
/// <param name="quote">Citation à valider.</param>
|
|
|
|
if (q != null)
|
|
|
|
public async Task validQuote(Quote quote)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
data.Remove(q);
|
|
|
|
throw new NotImplementedException();
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Met à jour une citation existante.
|
|
|
|
public async Task validQuote(Quote quote)
|
|
|
|
/// </summary>
|
|
|
|
{
|
|
|
|
/// <param name="quote">Citation mise à jour.</param>
|
|
|
|
throw new NotImplementedException();
|
|
|
|
public async Task updateQuote(Quote quote)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
var data = await getAllQuote();
|
|
|
|
public async Task updateQuote(Quote quote)
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == quote.Id);
|
|
|
|
|
|
|
|
if (q != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var data = await getAllQuote();
|
|
|
|
q.Content = quote.Content;
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == quote.Id);
|
|
|
|
q.Charac = quote.Charac;
|
|
|
|
if (q != null)
|
|
|
|
q.ImgPath = quote.ImgPath;
|
|
|
|
{
|
|
|
|
q.TitleSrc = quote.TitleSrc;
|
|
|
|
q.Content = quote.Content;
|
|
|
|
q.DateSrc = quote.DateSrc;
|
|
|
|
q.Charac = quote.Charac;
|
|
|
|
q.Langue = quote.Langue;
|
|
|
|
q.ImgPath = quote.ImgPath;
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
q.TitleSrc = quote.TitleSrc;
|
|
|
|
|
|
|
|
q.DateSrc = quote.DateSrc;
|
|
|
|
|
|
|
|
q.Langue = quote.Langue;
|
|
|
|
|
|
|
|
await saveQuoteJson(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Quote>> getAllQuote()
|
|
|
|
/// <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))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!File.Exists(_jsonFilePath))
|
|
|
|
Console.Out.WriteLine($"{_jsonFilePath} not found");
|
|
|
|
{
|
|
|
|
return new List<Quote>();
|
|
|
|
Console.Out.WriteLine($"{_jsonFilePath} not found");
|
|
|
|
|
|
|
|
return new List<Quote>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var json = await File.ReadAllTextAsync(_jsonFilePath);
|
|
|
|
|
|
|
|
return JsonSerializer.Deserialize<List<Quote>>(json) ?? new List<Quote>();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Quote>> getSomeQuote(int nb, int page)
|
|
|
|
var json = await File.ReadAllTextAsync(_jsonFilePath);
|
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var quotes = await getAllQuote();
|
|
|
|
if (nb > quotes.Count())
|
|
|
|
if((page - 1) * nb + nb > quotes.Count())
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (nb > quotes.Count())
|
|
|
|
return quotes.GetRange(0, quotes.Count());
|
|
|
|
{
|
|
|
|
|
|
|
|
return quotes.GetRange(0, quotes.Count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return quotes.GetRange(quotes.Count()-nb, nb);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
return quotes.GetRange(quotes.Count() - nb, nb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
public async Task<Quote> getOnequote(int id)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
|
|
|
|
|
|
return q;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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();
|
|
|
|
|
|
|
|
quotes = quotes.Where(q => q.IsValid == false).ToList();
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
if ((page - 1) * nb + nb > quotes.Count())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var data = await getAllQuote();
|
|
|
|
if (nb > quotes.Count())
|
|
|
|
var q = data.FirstOrDefault(p => p.Id == id);
|
|
|
|
|
|
|
|
if (q != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return q;
|
|
|
|
return quotes.GetRange(0, quotes.Count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return quotes.GetRange(quotes.Count() - nb, nb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
public async Task<List<Quote>> reserchQuote(string reserch, List<string> argument)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
/// <summary>
|
|
|
|
}
|
|
|
|
/// Récupère le nombre total de citations enregistrées.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
public async Task<List<Quote>> getAllQuoteInvalid()
|
|
|
|
/// <returns>Nombre total de citations.</returns>
|
|
|
|
{
|
|
|
|
public async Task<int> getNbQuote()
|
|
|
|
var quotes = await getAllQuote();
|
|
|
|
{
|
|
|
|
quotes = quotes.Where(q => q.IsValid == false).ToList();
|
|
|
|
var data = await getAllQuote();
|
|
|
|
return quotes;
|
|
|
|
return data.Count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Quote>> getSomeQuoteInvalid(int nb, int page)
|
|
|
|
/// <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))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var quotes = await getAllQuoteInvalid();
|
|
|
|
Console.Out.WriteLine($"{_char} not found");
|
|
|
|
if ((page - 1) * nb + nb > quotes.Count())
|
|
|
|
return new List<Character>();
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nb > quotes.Count())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return quotes.GetRange(0, quotes.Count());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return quotes.GetRange(quotes.Count() - nb, nb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return quotes.GetRange((page - 1) * nb, nb);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> getNbQuote()
|
|
|
|
var json = await File.ReadAllTextAsync(_char);
|
|
|
|
{
|
|
|
|
return JsonSerializer.Deserialize<List<Character>>(json) ?? new List<Character>();
|
|
|
|
var data = await getAllQuote();
|
|
|
|
}
|
|
|
|
return data.Count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Character>> getChar()
|
|
|
|
/// <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))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!File.Exists(_char))
|
|
|
|
Console.Out.WriteLine($"{_src} not found");
|
|
|
|
{
|
|
|
|
return new List<Source>();
|
|
|
|
Console.Out.WriteLine($"{_char} not found");
|
|
|
|
|
|
|
|
return new List<Character>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var json = await File.ReadAllTextAsync(_char);
|
|
|
|
|
|
|
|
return JsonSerializer.Deserialize<List<Character>>(json) ?? new List<Character>();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<Source>> getSrc()
|
|
|
|
var json = await File.ReadAllTextAsync(_src);
|
|
|
|
{
|
|
|
|
return JsonSerializer.Deserialize<List<Source>>(json) ?? new List<Source>();
|
|
|
|
if (!File.Exists(_src))
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.Out.WriteLine($"{_src} not found");
|
|
|
|
|
|
|
|
return new List<Source>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var json = await File.ReadAllTextAsync(_src);
|
|
|
|
|
|
|
|
return JsonSerializer.Deserialize<List<Source>>(json) ?? new List<Source>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|