diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IQuizService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IQuizService.cs
index 9c0dd95..f780355 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/IQuizService.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/IQuizService.cs
@@ -2,25 +2,66 @@ using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service
{
+ ///
+ /// Interface définissant les opérations de gestion des quiz.
+ ///
public interface IQuizService
{
+ ///
+ /// Ajoute un quiz.
+ ///
+ /// Quiz à ajouter.
public Task addQuiz(Quiz quiz);
+ ///
+ /// Met à jour un quiz existant.
+ ///
+ /// Quiz à mettre à jour.
public Task updateQuiz(Quiz quiz);
+ ///
+ /// Supprime un quiz par son identifiant.
+ ///
+ /// Identifiant du quiz à supprimer.
public Task removeQuiz(int id);
+ ///
+ /// Valide un quiz par son identifiant.
+ ///
+ /// Identifiant du quiz à valider.
public Task validateQuiz(int id);
+ ///
+ /// Récupère la liste de tous les quiz.
+ ///
+ /// Liste de tous les quiz.
public Task> getQuizzes();
+ ///
+ /// Récupère la liste des quiz en attente de validation.
+ ///
+ /// Liste des quiz non validés.
public Task> getQuizzesToValidate();
+ ///
+ /// Récupère un quiz spécifique par son identifiant.
+ ///
+ /// Identifiant du quiz.
+ /// Le quiz correspondant ou null s'il n'existe pas.
public Task getQuiz(int id);
+ ///
+ /// Récupère une liste paginée de quiz.
+ ///
+ /// Nombre de quiz par page.
+ /// Numéro de la page.
+ /// Liste des quiz correspondant à la pagination.
public Task> getSommeQuiz(int nb, int page);
+ ///
+ /// Récupère le nombre total de quiz enregistrés.
+ ///
+ /// Nombre total de quiz.
public Task getNbQuiz();
}
}
-
\ No newline at end of file
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs
index 6a4103f..468d6c8 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/IQuoteService.cs
@@ -2,32 +2,94 @@
namespace WF_WebAdmin.Service
{
+ ///
+ /// Interface définissant les opérations de gestion des citations.
+ ///
public interface IQuoteService
{
+ ///
+ /// Ajoute une citation.
+ ///
+ /// Citation à ajouter.
public Task addQuote(Quote quote);
+ ///
+ /// Supprime une citation.
+ ///
+ /// Citation à supprimer.
public Task removeQuote(Quote quote);
+ ///
+ /// Valide une citation.
+ ///
+ /// Citation à valider.
public Task validQuote(Quote quote);
+ ///
+ /// Met à jour une citation existante.
+ ///
+ /// Citation à mettre à jour.
public Task updateQuote(Quote quote);
+ ///
+ /// Récupère toutes les citations.
+ ///
+ /// Liste de toutes les citations.
public Task> getAllQuote();
+ ///
+ /// Récupère une liste paginée de citations.
+ ///
+ /// Nombre de citations par page.
+ /// Numéro de la page.
+ /// Liste des citations correspondant à la pagination.
public Task> getSomeQuote(int nb, int page);
+ ///
+ /// Récupère une citation spécifique par son identifiant.
+ ///
+ /// Identifiant de la citation.
+ /// La citation correspondante ou null si elle n'existe pas.
public Task getOnequote(int id);
+ ///
+ /// Recherche des citations en fonction d'un critère.
+ ///
+ /// Terme de recherche.
+ /// Liste des arguments pour affiner la recherche.
+ /// Liste des citations correspondant aux critères.
public Task> reserchQuote(string reserch, List argument);
+ ///
+ /// Récupère toutes les citations non validées.
+ ///
+ /// Liste des citations non validées.
public Task> getAllQuoteInvalid();
+ ///
+ /// Récupère une liste paginée de citations non validées.
+ ///
+ /// Nombre de citations par page.
+ /// Numéro de la page.
+ /// Liste des citations non validées correspondant à la pagination.
public Task> getSomeQuoteInvalid(int nb, int page);
+ ///
+ /// Récupère le nombre total de citations enregistrées.
+ ///
+ /// Nombre total de citations.
public Task getNbQuote();
+ ///
+ /// Récupère la liste des personnages associés aux citations.
+ ///
+ /// Liste des personnages.
public Task> getChar();
+ ///
+ /// Récupère la liste des sources associées aux citations.
+ ///
+ /// Liste des sources.
public Task> getSrc();
}
}
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs
index 7357e21..df9dbe6 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/IUserService.cs
@@ -2,24 +2,68 @@
namespace WF_WebAdmin.Service
{
+ ///
+ /// Interface définissant les opérations de gestion des utilisateurs.
+ ///
public interface IUserService
{
+ ///
+ /// Supprime un utilisateur du système.
+ ///
+ /// Utilisateur à supprimer.
public Task removeUser(User user);
+ ///
+ /// Met à jour le rôle d'un utilisateur.
+ ///
+ /// Utilisateur dont le rôle doit être mis à jour.
public Task updateRole(User user);
+ ///
+ /// Rétrograde le rôle d'un utilisateur.
+ ///
+ /// Utilisateur à rétrograder.
public Task downgradeRole(User user);
+ ///
+ /// Met à jour les informations d'un utilisateur.
+ ///
+ /// Utilisateur à mettre à jour.
public Task updateUser(User user);
+ ///
+ /// Récupère la liste complète des utilisateurs.
+ ///
+ /// Liste des utilisateurs.
public Task> getAllUser();
+ ///
+ /// Récupère une liste paginée d'utilisateurs.
+ ///
+ /// Nombre d'utilisateurs par page.
+ /// Numéro de la page.
+ /// Liste des utilisateurs correspondant à la pagination.
public Task> getSomeUser(int nb, int page);
+ ///
+ /// Récupère un utilisateur spécifique par son identifiant.
+ ///
+ /// Identifiant de l'utilisateur.
+ /// L'utilisateur correspondant ou null s'il n'existe pas.
public Task getOneUser(int id);
+ ///
+ /// Recherche des utilisateurs en fonction d'un critère.
+ ///
+ /// Terme de recherche.
+ /// Liste des arguments pour affiner la recherche.
+ /// Liste des utilisateurs correspondant aux critères.
public Task> reserchUsers(string reserch, List args);
+ ///
+ /// Récupère le nombre total d'utilisateurs enregistrés.
+ ///
+ /// Nombre total d'utilisateurs.
public Task getNbUser();
}
}
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs
index 7b6b662..17d9b99 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/QuizServiceStub.cs
@@ -1,106 +1,153 @@
-using System.Text.Json;
-using WF_WebAdmin.Model;
-
-namespace WF_WebAdmin.Service;
-
-public class QuizServiceStub: IQuizService
-{
- private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake_data_quiz.json");
-
- public async Task saveQuizJson(List quizzes)
- {
- var json = JsonSerializer.Serialize(quizzes, new JsonSerializerOptions { WriteIndented = true });
- await File.WriteAllTextAsync(_jsonFilePath, json);
- }
+using System.Text.Json;
+using WF_WebAdmin.Model;
- public async Task addQuiz(Quiz quiz)
+namespace WF_WebAdmin.Service
+{
+ ///
+ /// Service de gestion des quiz utilisant un fichier JSON comme stockage de données.
+ ///
+ public class QuizServiceStub : IQuizService
{
- var data = await getQuizzes();
- quiz.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1;
- data.Add(quiz);
- await saveQuizJson(data);
- }
+ private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake_data_quiz.json");
- public async Task updateQuiz(Quiz quiz)
- {
- var data = await getQuizzes();
- var existingQuiz = data.FirstOrDefault(q => q.Id == quiz.Id);
- if (existingQuiz != null)
- {
- existingQuiz.Question = quiz.Question;
- existingQuiz.AnswerA = quiz.AnswerA;
- existingQuiz.AnswerB = quiz.AnswerB;
- existingQuiz.AnswerC = quiz.AnswerC;
- existingQuiz.AnswerD = quiz.AnswerD;
- existingQuiz.CAnswer = quiz.CAnswer;
- existingQuiz.IsValid = quiz.IsValid;
- existingQuiz.UserProposition = quiz.UserProposition;
- await saveQuizJson(data);
+ ///
+ /// Sauvegarde la liste des quiz dans un fichier JSON.
+ ///
+ /// Liste des quiz à sauvegarder.
+ public async Task saveQuizJson(List quizzes)
+ {
+ var json = JsonSerializer.Serialize(quizzes, new JsonSerializerOptions { WriteIndented = true });
+ await File.WriteAllTextAsync(_jsonFilePath, json);
}
- }
- public async Task removeQuiz(int id)
- {
- var data = await getQuizzes();
- var quiz = data.FirstOrDefault(q => q.Id == id);
- if (quiz != null)
- {
- data.Remove(quiz);
- await saveQuizJson(data);
+ ///
+ /// Ajoute un quiz à la liste et le sauvegarde dans le fichier JSON.
+ ///
+ /// Quiz à ajouter.
+ public async Task addQuiz(Quiz quiz)
+ {
+ var data = await getQuizzes();
+ quiz.Id = data.Count > 0 ? data.Max(p => p.Id) + 1 : 1;
+ data.Add(quiz);
+ await saveQuizJson(data);
}
- }
- public Task validateQuiz(int id)
- {
- throw new NotImplementedException();
- }
+ ///
+ /// Met à jour un quiz existant dans la liste et le sauvegarde.
+ ///
+ /// Quiz mis à jour.
+ public async Task updateQuiz(Quiz quiz)
+ {
+ var data = await getQuizzes();
+ var existingQuiz = data.FirstOrDefault(q => q.Id == quiz.Id);
+ if (existingQuiz != null)
+ {
+ existingQuiz.Question = quiz.Question;
+ existingQuiz.AnswerA = quiz.AnswerA;
+ existingQuiz.AnswerB = quiz.AnswerB;
+ existingQuiz.AnswerC = quiz.AnswerC;
+ existingQuiz.AnswerD = quiz.AnswerD;
+ existingQuiz.CAnswer = quiz.CAnswer;
+ existingQuiz.IsValid = quiz.IsValid;
+ existingQuiz.UserProposition = quiz.UserProposition;
+ await saveQuizJson(data);
+ }
+ }
- public async Task> getQuizzes()
- {
- if (!File.Exists(_jsonFilePath))
- {
- Console.Out.WriteLine($"{_jsonFilePath} not found");
- return new List();
- }
-
- var json = await File.ReadAllTextAsync(_jsonFilePath);
- return JsonSerializer.Deserialize>(json) ?? new List();
- }
+ ///
+ /// Supprime un quiz de la liste et met à jour le fichier JSON.
+ ///
+ /// Identifiant du quiz à supprimer.
+ public async Task removeQuiz(int id)
+ {
+ var data = await getQuizzes();
+ var quiz = data.FirstOrDefault(q => q.Id == id);
+ if (quiz != null)
+ {
+ data.Remove(quiz);
+ await saveQuizJson(data);
+ }
+ }
- public async Task> getQuizzesToValidate()
- {
- var quizzes = await getQuizzes();
- return quizzes.Where(quiz => quiz.IsValid == false).ToList();
- }
+ ///
+ /// Valide un quiz (non implémenté).
+ ///
+ /// Identifiant du quiz à valider.
+ public Task validateQuiz(int id)
+ {
+ throw new NotImplementedException();
+ }
- public async Task getQuiz(int id)
- {
- var data = await getQuizzes();
- var q = data.FirstOrDefault(p => p.Id == id);
- if (q != null)
+ ///
+ /// Récupère la liste complète des quiz à partir du fichier JSON.
+ ///
+ /// Liste des quiz.
+ public async Task> getQuizzes()
{
- return q;
+ if (!File.Exists(_jsonFilePath))
+ {
+ Console.Out.WriteLine($"{_jsonFilePath} not found");
+ return new List();
+ }
+
+ var json = await File.ReadAllTextAsync(_jsonFilePath);
+ return JsonSerializer.Deserialize>(json) ?? new List();
}
- return null;
- }
- public async Task> getSommeQuiz(int nb, int page)
- {
- var data = await getQuizzes();
- if ((page - 1) * nb + nb > data.Count())
+ ///
+ /// Récupère la liste des quiz non validés.
+ ///
+ /// Liste des quiz en attente de validation.
+ public async Task> getQuizzesToValidate()
{
- if(nb > data.Count())
+ var quizzes = await getQuizzes();
+ return quizzes.Where(quiz => quiz.IsValid == false).ToList();
+ }
+
+ ///
+ /// Récupère un quiz spécifique par son identifiant.
+ ///
+ /// Identifiant du quiz.
+ /// Le quiz correspondant ou null s'il n'existe pas.
+ public async Task getQuiz(int id)
+ {
+ var data = await getQuizzes();
+ var q = data.FirstOrDefault(p => p.Id == id);
+ if (q != null)
{
- return data.GetRange(0, data.Count()-1);
+ return q;
}
- return data.GetRange(data.Count() - nb, nb);
+ return null;
}
- return data.GetRange((page - 1) * nb, nb);
- }
- public async Task getNbQuiz()
- {
- var data = await getQuizzes();
- return data.Count;
+ ///
+ /// Récupère une liste paginée de quiz.
+ ///
+ /// Nombre de quiz par page.
+ /// Numéro de la page.
+ /// Liste des quiz correspondant à la pagination.
+ public async Task> getSommeQuiz(int nb, int page)
+ {
+ var data = await getQuizzes();
+ if ((page - 1) * nb + nb > data.Count())
+ {
+ if (nb > data.Count())
+ {
+ return data.GetRange(0, data.Count() - 1);
+ }
+ return data.GetRange(data.Count() - nb, nb);
+ }
+ return data.GetRange((page - 1) * nb, nb);
+ }
+
+ ///
+ /// Récupère le nombre total de quiz enregistrés.
+ ///
+ /// Nombre total de quiz.
+ public async Task getNbQuiz()
+ {
+ var data = await getQuizzes();
+ return data.Count;
+ }
}
-}
+}
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs
index 4417c5b..643c59c 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceLocal.cs
@@ -4,29 +4,30 @@ using Npgsql;
namespace WF_WebAdmin.Service
{
- public class QuoteServiceLocal: IQuoteService
+ ///
+ /// Service de gestion des citations utilisant une base de données PostgreSQL.
+ ///
+ public class QuoteServiceLocal : IQuoteService
{
private readonly string? _connectionString = "Host=localhost;Port=5432;Username=loguichard3;Password=Reglisse15.;Database=dbloguichard3";
-
-
-
+ ///
+ /// Ajoute une nouvelle citation à la base de données PostgreSQL.
+ ///
+ /// Citation à ajouter.
+ /// Un objet représentant la citation ajoutée.
public async Task AddQuoteAsync(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
- // Utilisation de NpgsqlConnection pour PostgreSQL
using (var connection = new NpgsqlConnection(_connectionString))
{
- // Définir la requête SQL d'insertion
var commandText = "INSERT INTO Quote (content, langue, reason, id_source, id_caracter, id_user_verif, img_path) " +
"VALUES (@content, @langue, @reason, @source, @character, @user, @img_path)";
- // Créer une commande Npgsql
var command = new NpgsqlCommand(commandText, connection);
-
/*
// Ajouter des paramètres à la commande
command.Parameters.AddWithValue("@content", quote.Content);
@@ -38,33 +39,29 @@ namespace WF_WebAdmin.Service
command.Parameters.AddWithValue("@img_path", quote.ImgPath);
*/
-
try
{
- // Ouvrir la connexion à la base de données
await connection.OpenAsync();
-
- // Exécuter la commande d'insertion
await command.ExecuteNonQueryAsync();
}
catch (Exception ex)
{
- // Gérer les erreurs ici (par exemple, afficher ou enregistrer les erreurs)
Console.WriteLine($"Une erreur est survenue lors de l'ajout de la citation : {ex.Message}");
}
finally
{
- // Fermer la connexion (automatiquement géré avec `using`, mais ajouté pour explicitement montrer le processus)
await connection.CloseAsync();
}
}
- // Retourner l'objet DTO pour que vous puissiez l'utiliser ailleurs dans votre application
return quoteDTO;
}
-
- public Task RemoveQuote(Quote quote)
+ ///
+ /// Supprime une citation de la base de données.
+ ///
+ /// Citation à supprimer.
+ public Task RemoveQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
QuoteDTO quoteDTO = extension.QuoteToDTO(quote);
@@ -72,6 +69,10 @@ namespace WF_WebAdmin.Service
return Task.FromResult(quoteDTO);
}
+ ///
+ /// Valide une citation.
+ ///
+ /// Citation à valider.
public Task validQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
@@ -80,6 +81,10 @@ namespace WF_WebAdmin.Service
return Task.FromResult(quoteDTO);
}
+ ///
+ /// Met à jour une citation existante.
+ ///
+ /// Citation mise à jour.
public Task updateQuote(Quote quote)
{
QuoteExtension extension = new QuoteExtension();
@@ -88,61 +93,89 @@ namespace WF_WebAdmin.Service
return Task.FromResult(quoteDTO);
}
-
-
-
-
-
+ ///
+ /// Ajoute une citation (non implémenté).
+ ///
public Task addQuote(Quote quote)
{
throw new NotImplementedException();
}
+ ///
+ /// Supprime une citation (non implémenté).
+ ///
public Task removeQuote(Quote quote)
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère toutes les citations (non implémenté).
+ ///
public Task> getAllQuote()
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère un ensemble de citations paginées (non implémenté).
+ ///
public Task> getSomeQuote(int nb, int page)
{
throw new NotImplementedException();
}
+ ///
+ /// Recherche des citations selon des critères spécifiques (non implémenté).
+ ///
public Task> reserchQuote(string reserch, List argument)
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère toutes les citations invalides (non implémenté).
+ ///
public Task> getAllQuoteInvalid()
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère une liste paginée de citations invalides (non implémenté).
+ ///
public Task> getSomeQuoteInvalid(int nb, int page)
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère une citation spécifique en fonction de son ID (non implémenté).
+ ///
public Task getOnequote(int id)
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère le nombre total de citations enregistrées (non implémenté).
+ ///
public Task getNbQuote()
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère la liste des personnages (non implémenté).
+ ///
public Task> getChar()
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère la liste des sources (non implémenté).
+ ///
public Task> getSrc()
{
throw new NotImplementedException();
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs
index fcf6102..e697ed4 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/QuoteServiceStub.cs
@@ -3,149 +3,210 @@ using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service;
- public class QuoteServiceStub : IQuoteService
- {
+///
+/// Service de gestion des citations utilisant un fichier JSON comme stockage.
+///
+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");
+ ///
+ /// Sauvegarde la liste des citations dans le fichier JSON.
+ ///
+ /// Liste des citations à sauvegarder.
public async Task saveQuoteJson(List quotes)
+ {
+ var json = JsonSerializer.Serialize(quotes, new JsonSerializerOptions { WriteIndented = true });
+ await File.WriteAllTextAsync(_jsonFilePath, json);
+ }
+
+ ///
+ /// Ajoute une nouvelle citation et l'enregistre dans le fichier JSON.
+ ///
+ /// Citation à ajouter.
+ 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);
+ }
+
+ ///
+ /// Supprime une citation et met à jour le fichier JSON.
+ ///
+ /// Citation à supprimer.
+ 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 });
- 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);
+ data.Remove(q);
await saveQuoteJson(data);
}
+ }
- public async Task removeQuote(Quote quote)
- {
- var data = await getAllQuote();
- var q = data.FirstOrDefault(p => p.Id == quote.Id);
- if (q != null)
- {
- data.Remove(q);
- await saveQuoteJson(data);
- }
- }
-
- public async Task validQuote(Quote quote)
- {
- throw new NotImplementedException();
- }
-
- public async Task updateQuote(Quote quote)
+ ///
+ /// Marque une citation comme valide.
+ ///
+ /// Citation à valider.
+ public async Task validQuote(Quote quote)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Met à jour une citation existante.
+ ///
+ /// Citation mise à jour.
+ public async Task updateQuote(Quote quote)
+ {
+ var data = await getAllQuote();
+ var q = data.FirstOrDefault(p => p.Id == quote.Id);
+ if (q != null)
{
- var data = await getAllQuote();
- var q = data.FirstOrDefault(p => p.Id == quote.Id);
- if (q != null)
- {
- q.Content = quote.Content;
- q.Charac = quote.Charac;
- q.ImgPath = quote.ImgPath;
- q.TitleSrc = quote.TitleSrc;
- q.DateSrc = quote.DateSrc;
- q.Langue = quote.Langue;
- await saveQuoteJson(data);
- }
+ q.Content = quote.Content;
+ q.Charac = quote.Charac;
+ q.ImgPath = quote.ImgPath;
+ q.TitleSrc = quote.TitleSrc;
+ q.DateSrc = quote.DateSrc;
+ q.Langue = quote.Langue;
+ await saveQuoteJson(data);
}
+ }
- public async Task> getAllQuote()
+ ///
+ /// Récupère toutes les citations stockées dans le fichier JSON.
+ ///
+ /// Une liste de citations.
+ public async Task> getAllQuote()
+ {
+ if (!File.Exists(_jsonFilePath))
{
- if (!File.Exists(_jsonFilePath))
- {
- Console.Out.WriteLine($"{_jsonFilePath} not found");
- return new List();
- }
-
- var json = await File.ReadAllTextAsync(_jsonFilePath);
- return JsonSerializer.Deserialize>(json) ?? new List();
+ Console.Out.WriteLine($"{_jsonFilePath} not found");
+ return new List();
}
- public async Task> getSomeQuote(int nb, int page)
+ var json = await File.ReadAllTextAsync(_jsonFilePath);
+ return JsonSerializer.Deserialize>(json) ?? new List();
+ }
+
+ ///
+ /// Récupère une liste paginée de citations.
+ ///
+ /// Nombre de citations par page.
+ /// Numéro de la page.
+ /// Une liste de citations correspondant à la page demandée.
+ public async Task> getSomeQuote(int nb, int page)
+ {
+ var quotes = await getAllQuote();
+ if ((page - 1) * nb + nb > quotes.Count())
{
- var quotes = await getAllQuote();
- if((page - 1) * nb + nb > quotes.Count())
+ if (nb > quotes.Count())
{
- if (nb > quotes.Count())
- {
- return quotes.GetRange(0, quotes.Count());
- }
- return quotes.GetRange(quotes.Count()-nb, nb);
+ return quotes.GetRange(0, quotes.Count());
}
- return quotes.GetRange((page - 1) * nb, nb);
+ return quotes.GetRange(quotes.Count() - nb, nb);
}
-
- public async Task getOnequote(int id)
+ return quotes.GetRange((page - 1) * nb, nb);
+ }
+
+ ///
+ /// Récupère une citation spécifique en fonction de son ID.
+ ///
+ /// ID de la citation recherchée.
+ /// La citation correspondante ou null si elle n'existe pas.
+ public async Task getOnequote(int id)
+ {
+ var data = await getAllQuote();
+ var q = data.FirstOrDefault(p => p.Id == id);
+ return q;
+ }
+
+ ///
+ /// Recherche des citations selon des critères spécifiques.
+ ///
+ /// Terme de recherche.
+ /// Liste d'arguments pour affiner la recherche.
+ /// Une liste de citations correspondant aux critères de recherche.
+ public async Task> reserchQuote(string reserch, List argument)
+ {
+ throw new NotImplementedException();
+ }
+
+ ///
+ /// Récupère toutes les citations invalides.
+ ///
+ /// Une liste de citations non validées.
+ public async Task> getAllQuoteInvalid()
+ {
+ var quotes = await getAllQuote();
+ quotes = quotes.Where(q => q.IsValid == false).ToList();
+ return quotes;
+ }
+
+ ///
+ /// Récupère une liste paginée de citations invalides.
+ ///
+ /// Nombre de citations par page.
+ /// Numéro de la page.
+ /// Une liste de citations non validées correspondant à la page demandée.
+ public async Task> getSomeQuoteInvalid(int nb, int page)
+ {
+ var quotes = await getAllQuoteInvalid();
+ if ((page - 1) * nb + nb > quotes.Count())
{
- var data = await getAllQuote();
- var q = data.FirstOrDefault(p => p.Id == id);
- if (q != null)
+ if (nb > quotes.Count())
{
- return q;
+ return quotes.GetRange(0, quotes.Count());
}
- return null;
- }
-
- public async Task> reserchQuote(string reserch, List argument)
- {
- throw new NotImplementedException();
+ return quotes.GetRange(quotes.Count() - nb, nb);
}
-
- public async Task> getAllQuoteInvalid()
- {
- var quotes = await getAllQuote();
- quotes = quotes.Where(q => q.IsValid == false).ToList();
- return quotes;
- }
-
- public async Task> getSomeQuoteInvalid(int nb, int page)
+ return quotes.GetRange((page - 1) * nb, nb);
+ }
+
+ ///
+ /// Récupère le nombre total de citations enregistrées.
+ ///
+ /// Nombre total de citations.
+ public async Task getNbQuote()
+ {
+ var data = await getAllQuote();
+ return data.Count;
+ }
+
+ ///
+ /// Récupère la liste des personnages depuis le fichier JSON.
+ ///
+ /// Une liste de personnages.
+ public async Task> getChar()
+ {
+ if (!File.Exists(_char))
{
- var quotes = await getAllQuoteInvalid();
- 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((page - 1) * nb, nb);
+ Console.Out.WriteLine($"{_char} not found");
+ return new List();
}
- public async Task getNbQuote()
- {
- var data = await getAllQuote();
- return data.Count;
- }
+ var json = await File.ReadAllTextAsync(_char);
+ return JsonSerializer.Deserialize>(json) ?? new List();
+ }
- public async Task> getChar()
+ ///
+ /// Récupère la liste des sources depuis le fichier JSON.
+ ///
+ /// Une liste de sources.
+ public async Task> getSrc()
+ {
+ if (!File.Exists(_src))
{
- if (!File.Exists(_char))
- {
- Console.Out.WriteLine($"{_char} not found");
- return new List();
- }
-
- var json = await File.ReadAllTextAsync(_char);
- return JsonSerializer.Deserialize>(json) ?? new List();
+ Console.Out.WriteLine($"{_src} not found");
+ return new List();
}
- public async Task> getSrc()
- {
- if (!File.Exists(_src))
- {
- Console.Out.WriteLine($"{_src} not found");
- return new List();
- }
-
- var json = await File.ReadAllTextAsync(_src);
- return JsonSerializer.Deserialize>(json) ?? new List();
- }
+ var json = await File.ReadAllTextAsync(_src);
+ return JsonSerializer.Deserialize>(json) ?? new List();
+ }
}
-
\ No newline at end of file
diff --git a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs
index 67cb03f..51c1545 100644
--- a/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs
+++ b/WF-WebAdmin/WF-WebAdmin/Service/UserServiceStub.cs
@@ -3,17 +3,27 @@ using WF_WebAdmin.Model;
namespace WF_WebAdmin.Service;
+///
+/// Service de gestion des utilisateurs utilisant un fichier JSON comme stockage.
+///
public class UserServiceStub : IUserService
{
private readonly string _jsonFilePath = Path.Combine(Environment.CurrentDirectory, "wwwroot", "fake_data_users.json");
-
+ ///
+ /// Sauvegarde la liste des utilisateurs dans le fichier JSON.
+ ///
+ /// Liste des utilisateurs à sauvegarder.
public async Task saveUsersJson(List users)
{
var json = JsonSerializer.Serialize(users, new JsonSerializerOptions { WriteIndented = true });
await File.WriteAllTextAsync(_jsonFilePath, json);
}
+ ///
+ /// Supprime un utilisateur de la liste et met à jour le fichier JSON.
+ ///
+ /// Utilisateur à supprimer.
public async Task removeUser(User user)
{
var data = await getAllUser();
@@ -25,18 +35,30 @@ public class UserServiceStub : IUserService
}
}
+ ///
+ /// Met à jour le rôle d'un utilisateur pour le passer en administrateur.
+ ///
+ /// Utilisateur à promouvoir.
public Task updateRole(User user)
{
user.IsAdmin = true;
return updateUser(user);
}
+ ///
+ /// Rétrograde un administrateur en utilisateur normal.
+ ///
+ /// Utilisateur à rétrograder.
public Task downgradeRole(User user)
{
user.IsAdmin = false;
return updateUser(user);
}
+ ///
+ /// Récupère tous les utilisateurs stockés dans le fichier JSON.
+ ///
+ /// Une liste d'utilisateurs.
public async Task> getAllUser()
{
if (!File.Exists(_jsonFilePath))
@@ -49,6 +71,12 @@ public class UserServiceStub : IUserService
return JsonSerializer.Deserialize>(json) ?? new List();
}
+ ///
+ /// Récupère une liste paginée d'utilisateurs.
+ ///
+ /// Nombre d'utilisateurs par page.
+ /// Numéro de la page.
+ /// Une liste d'utilisateurs correspondant à la page demandée.
public async Task> getSomeUser(int nb, int page)
{
var users = await getAllUser();
@@ -59,39 +87,54 @@ public class UserServiceStub : IUserService
return users.GetRange((page - 1) * nb, nb);
}
+ ///
+ /// Récupère un utilisateur spécifique en fonction de son ID.
+ ///
+ /// ID de l'utilisateur recherché.
+ /// L'utilisateur correspondant à l'ID ou null s'il n'existe pas.
public async Task getOneUser(int id)
{
var data = await getAllUser();
var u = data.FirstOrDefault(p => p.Id == id);
- if (u != null)
- {
- return u;
- }
- return null;
+ return u;
}
+ ///
+ /// Recherche des utilisateurs selon des critères spécifiques.
+ ///
+ /// Terme de recherche.
+ /// Liste des arguments supplémentaires pour affiner la recherche.
+ /// Une liste d'utilisateurs correspondant aux critères de recherche.
public Task> reserchUsers(string reserch, List args)
{
throw new NotImplementedException();
}
+ ///
+ /// Récupère le nombre total d'utilisateurs enregistrés.
+ ///
+ /// Nombre total d'utilisateurs.
public async Task getNbUser()
{
var data = await getAllUser();
return data.Count;
}
+ ///
+ /// Met à jour les informations d'un utilisateur existant.
+ ///
+ /// Utilisateur avec les nouvelles informations.
public async Task updateUser(User user)
{
- var data = await getAllUser();
- var person = data.FirstOrDefault(p => p.Id == user.Id);
- if (person != null)
- {
- person.Name = user.Name;
- person.Email = user.Email;
- person.Image = user.Image;
- person.IsAdmin = user.IsAdmin;
- await saveUsersJson(data);
- }
+ var data = await getAllUser();
+ var person = data.FirstOrDefault(p => p.Id == user.Id);
+ if (person != null)
+ {
+ person.Name = user.Name;
+ person.Email = user.Email;
+ person.Image = user.Image;
+ person.IsAdmin = user.IsAdmin;
+ await saveUsersJson(data);
+ }
}
-}
\ No newline at end of file
+}