From f193aa47e141861b04cca263da9a811efc743800 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Tue, 31 Mar 2026 13:53:42 +0200 Subject: [PATCH 01/12] add TODO --- Webzine.Repository.Contracts/IArtisteRepository.cs | 2 +- Webzine.Repository/DbArtisteRepository.cs | 2 +- Webzine.Repository/DbStyleRepository.cs | 4 ++-- Webzine.Repository/DbTitreRepository.cs | 4 ++-- Webzine.Repository/LocalArtisteRepository.cs | 10 +++++----- Webzine.Repository/LocalCommentaireRepository.cs | 2 +- Webzine.Repository/LocalTitreRepository.cs | 8 +++++--- .../Administration/Controllers/DashboardController.cs | 2 +- .../Controllers/RechercheController.cs | 4 ++-- Webzine.WebApplication/Controllers/TitreController.cs | 2 +- Webzine.WebApplication/Program.cs | 2 -- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Webzine.Repository.Contracts/IArtisteRepository.cs b/Webzine.Repository.Contracts/IArtisteRepository.cs index 1ab6e83..e6dc1be 100644 --- a/Webzine.Repository.Contracts/IArtisteRepository.cs +++ b/Webzine.Repository.Contracts/IArtisteRepository.cs @@ -4,7 +4,7 @@ namespace Webzine.Repository.Contracts /// /// Défini une interface pour gérer les opérations de base de données liées aux artistes. - /// + /// // TODO interface n'est pas que liée à la bdd, elle est aussi utilisée pour la gestion en mémoire public interface IArtisteRepository { /// diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index 800f5af..e317f4b 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -13,7 +13,7 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. + /// Utilise en injection de dépendances. // TODO commentaire faux. /// public class DbArtisteRepository : IArtisteRepository { diff --git a/Webzine.Repository/DbStyleRepository.cs b/Webzine.Repository/DbStyleRepository.cs index c350a4f..4f5c20c 100644 --- a/Webzine.Repository/DbStyleRepository.cs +++ b/Webzine.Repository/DbStyleRepository.cs @@ -93,10 +93,10 @@ public class DbStyleRepository : IStyleRepository { this.logger.LogDebug("Recherche du style avec l'ID: {Id}", id); - if (id <= 0) + if (id <= 0) // TODO à supprimer, c'est au controller de vérifier la validité de l'id { this.logger.LogWarning("Tentative de recherche d'un style avec un Id invalide: {Id}", id); - return new Style(); + return new Style(); // TODO pas de retour d'objet vide } this.logger.LogDebug("Préparation de la requête avec inclusion des titres"); diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index 9c0ac04..99bef26 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -33,7 +33,7 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Ajout d'un nouveau titre: {Libelle}", titre.Libelle); - this.logger.LogDebug("Début de l'ajout du titre en base de données"); + this.logger.LogDebug("Début de l'ajout du titre en base de données"); // TODO trop de logs this.context.Titres.Add(titre); this.context.SaveChanges(); @@ -289,7 +289,7 @@ public class DbTitreRepository : ITitreRepository { try { - this.logger.LogDebug("Récupération de tous les titres"); + this.logger.LogDebug("Récupération de tous les titres"); // TODO trop de logs this.logger.LogDebug("Préparation de la requête avec les inclusions Artiste et Styles"); var titres = this.context.Titres diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index 67ebabf..70994e4 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -11,20 +11,20 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. + /// Utilise en injection de dépendances. // TODO faux. /// public class LocalArtisteRepository : IArtisteRepository { private readonly ILogger logger; - // private readonly List artistes; + // private readonly List artistes; // TODO code mort private readonly InMemoryDataStore dataStore; /// /// Initializes a new instance of the class. /// Est liéee à une liste d'artistes en local et utilise un logger pour enregistrer les opérations effectuées sur les artistes. /// - /// La liste des artistes à initialiser. Ne peut pas être null. + /// La liste des artistes à initialiser. Ne peut pas être null. // TODO pas le bon paramètre /// Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null. public LocalArtisteRepository(InMemoryDataStore dataStore, ILogger logger) { @@ -37,7 +37,7 @@ namespace Webzine.Repository /// public void Add(Artiste artiste) { - throw new NotSupportedException("Mode Local"); + throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// @@ -52,7 +52,7 @@ namespace Webzine.Repository var artiste = this.dataStore.Artistes.First(a => a.IdArtiste == id); if (artiste == null) { - return new Artiste(); + return new Artiste(); // TODO ne pas retourner un objet vide, FirstOrDefault et gérer le null dans le controller } return artiste; diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index 8a91ab8..a0b1da3 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -38,7 +38,7 @@ namespace Webzine.Repository /// public void Add(Commentaire commentaire) { - throw new NotSupportedException("Mode Local"); + throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index ff8832c..bc1e488 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -34,7 +34,9 @@ public class LocalTitreRepository : ITitreRepository /// public int Count() { - var count = this.dataStore.Titres.Count(); + var count = this.dataStore.Titres.Count(); // TODO une seule ligne, et attention car les deux méthodes s'appelent pareil, + + // il faut faire attention à ne pas confondre avec la méthode Count() de l'interface ITitreRepository return count; } @@ -62,14 +64,14 @@ public class LocalTitreRepository : ITitreRepository /// public void IncrementNbLikes(Titre titre) { - titre.NbLikes++; + titre.NbLikes++; // TODO rien n'est enregistré } /// public IEnumerable Search(string mot) { return this.dataStore.Titres - .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); + .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); // TODO attention au null, et à la casse, et à l'indexation pour les performances } /// diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs index 2f314ad..753ebeb 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs @@ -6,7 +6,7 @@ using Webzine.Repository.Contracts; using Webzine.WebApplication.Areas.Administration.ViewModels; [Area("Administration")] -public class DashboardController : Controller +public class DashboardController : Controller // TODO à refaire { private readonly ILogger logger; private readonly IStyleRepository styleRepository; diff --git a/Webzine.WebApplication/Controllers/RechercheController.cs b/Webzine.WebApplication/Controllers/RechercheController.cs index 4676c9d..24c6a07 100644 --- a/Webzine.WebApplication/Controllers/RechercheController.cs +++ b/Webzine.WebApplication/Controllers/RechercheController.cs @@ -11,7 +11,7 @@ namespace Webzine.WebApplication.Controllers using Webzine.WebApplication.ViewModels.Titre; [Route("recherche")] - public class RechercheController : Controller + public class RechercheController : Controller // TODO à modifier intégralement et à commenter { private readonly ILogger logger; private readonly ITitreRepository titreRepository; @@ -46,7 +46,7 @@ namespace Webzine.WebApplication.Controllers .Where(a => a != null && !string.IsNullOrWhiteSpace(a.Nom) && !string.IsNullOrWhiteSpace(mot) - && a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase)) + && a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase)) // TODO OrdinalIgnoreCase pas bien .DistinctBy(a => a!.IdArtiste) .OrderBy(a => a!.Nom) .Select(a => new RechercheArtisteItem diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index 01b1239..60c3ae0 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -82,7 +82,7 @@ namespace Webzine.WebApplication.Controllers /// /// Nom du style musical. /// Vue contenant la liste filtree. - [HttpGet("style/{style}")] + [HttpGet("style/{style}")] // TODO pas de route écrite en dur dans le controller public IActionResult Style(string style) { this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style); diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 2a19bd7..fa32221 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -2,10 +2,8 @@ #pragma warning disable SA1200 using Microsoft.EntityFrameworkCore; - using NLog; using NLog.Web; - using Webzine.EntitiesContext; using Webzine.Entity; using Webzine.Entity.Fixtures; From 61f00f339b1ea19e2b9076031520cd82f3a315ff Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Tue, 31 Mar 2026 14:00:28 +0200 Subject: [PATCH 02/12] #146 Rerun dotnet format. --- Webzine.WebApplication/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index fa32221..2a19bd7 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -2,8 +2,10 @@ #pragma warning disable SA1200 using Microsoft.EntityFrameworkCore; + using NLog; using NLog.Web; + using Webzine.EntitiesContext; using Webzine.Entity; using Webzine.Entity.Fixtures; From b2dc449adb9deb8e41920e2989da72814f2d7a20 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Tue, 31 Mar 2026 13:53:42 +0200 Subject: [PATCH 03/12] add TODO --- Webzine.Repository.Contracts/IArtisteRepository.cs | 2 +- Webzine.Repository/DbArtisteRepository.cs | 2 +- Webzine.Repository/DbStyleRepository.cs | 4 ++-- Webzine.Repository/DbTitreRepository.cs | 4 ++-- Webzine.Repository/LocalArtisteRepository.cs | 10 +++++----- Webzine.Repository/LocalCommentaireRepository.cs | 2 +- Webzine.Repository/LocalTitreRepository.cs | 8 +++++--- .../Controllers/DashboardController.cs | 2 +- .../Controllers/RechercheController.cs | 13 +++++++++++-- .../Controllers/TitreController.cs | 2 +- Webzine.WebApplication/Program.cs | 2 -- 11 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Webzine.Repository.Contracts/IArtisteRepository.cs b/Webzine.Repository.Contracts/IArtisteRepository.cs index bc13f76..3c873c9 100644 --- a/Webzine.Repository.Contracts/IArtisteRepository.cs +++ b/Webzine.Repository.Contracts/IArtisteRepository.cs @@ -4,7 +4,7 @@ namespace Webzine.Repository.Contracts /// /// Défini une interface pour gérer les opérations de base de données liées aux artistes. - /// + /// // TODO interface n'est pas que liée à la bdd, elle est aussi utilisée pour la gestion en mémoire public interface IArtisteRepository { /// diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index c27c1d7..d34628e 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -13,7 +13,7 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. + /// Utilise en injection de dépendances. // TODO commentaire faux. /// public class DbArtisteRepository : IArtisteRepository { diff --git a/Webzine.Repository/DbStyleRepository.cs b/Webzine.Repository/DbStyleRepository.cs index c350a4f..4f5c20c 100644 --- a/Webzine.Repository/DbStyleRepository.cs +++ b/Webzine.Repository/DbStyleRepository.cs @@ -93,10 +93,10 @@ public class DbStyleRepository : IStyleRepository { this.logger.LogDebug("Recherche du style avec l'ID: {Id}", id); - if (id <= 0) + if (id <= 0) // TODO à supprimer, c'est au controller de vérifier la validité de l'id { this.logger.LogWarning("Tentative de recherche d'un style avec un Id invalide: {Id}", id); - return new Style(); + return new Style(); // TODO pas de retour d'objet vide } this.logger.LogDebug("Préparation de la requête avec inclusion des titres"); diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index ab362b9..9390c15 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -33,7 +33,7 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Ajout d'un nouveau titre: {Libelle}", titre.Libelle); - this.logger.LogDebug("Début de l'ajout du titre en base de données"); + this.logger.LogDebug("Début de l'ajout du titre en base de données"); // TODO trop de logs this.context.Titres.Add(titre); this.context.SaveChanges(); @@ -288,7 +288,7 @@ public class DbTitreRepository : ITitreRepository { try { - this.logger.LogDebug("Récupération de tous les titres"); + this.logger.LogDebug("Récupération de tous les titres"); // TODO trop de logs this.logger.LogDebug("Préparation de la requête avec les inclusions Artiste et Styles"); var titres = this.context.Titres diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index 69021c5..a65fe44 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -11,20 +11,20 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. + /// Utilise en injection de dépendances. // TODO faux. /// public class LocalArtisteRepository : IArtisteRepository { private readonly ILogger logger; - // private readonly List artistes; + // private readonly List artistes; // TODO code mort private readonly InMemoryDataStore dataStore; /// /// Initializes a new instance of the class. /// Est liéee à une liste d'artistes en local et utilise un logger pour enregistrer les opérations effectuées sur les artistes. /// - /// La liste des artistes à initialiser. Ne peut pas être null. + /// La liste des artistes à initialiser. Ne peut pas être null. // TODO pas le bon paramètre /// Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null. public LocalArtisteRepository(InMemoryDataStore dataStore, ILogger logger) { @@ -37,7 +37,7 @@ namespace Webzine.Repository /// public void Add(Artiste artiste) { - throw new NotSupportedException("Mode Local"); + throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// @@ -52,7 +52,7 @@ namespace Webzine.Repository var artiste = this.dataStore.Artistes.First(a => a.IdArtiste == id); if (artiste == null) { - return new Artiste(); + return new Artiste(); // TODO ne pas retourner un objet vide, FirstOrDefault et gérer le null dans le controller } return artiste; diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index 8a91ab8..a0b1da3 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -38,7 +38,7 @@ namespace Webzine.Repository /// public void Add(Commentaire commentaire) { - throw new NotSupportedException("Mode Local"); + throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index ff8832c..bc1e488 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -34,7 +34,9 @@ public class LocalTitreRepository : ITitreRepository /// public int Count() { - var count = this.dataStore.Titres.Count(); + var count = this.dataStore.Titres.Count(); // TODO une seule ligne, et attention car les deux méthodes s'appelent pareil, + + // il faut faire attention à ne pas confondre avec la méthode Count() de l'interface ITitreRepository return count; } @@ -62,14 +64,14 @@ public class LocalTitreRepository : ITitreRepository /// public void IncrementNbLikes(Titre titre) { - titre.NbLikes++; + titre.NbLikes++; // TODO rien n'est enregistré } /// public IEnumerable Search(string mot) { return this.dataStore.Titres - .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); + .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); // TODO attention au null, et à la casse, et à l'indexation pour les performances } /// diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs index 2f314ad..753ebeb 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/DashboardController.cs @@ -6,7 +6,7 @@ using Webzine.Repository.Contracts; using Webzine.WebApplication.Areas.Administration.ViewModels; [Area("Administration")] -public class DashboardController : Controller +public class DashboardController : Controller // TODO à refaire { private readonly ILogger logger; private readonly IStyleRepository styleRepository; diff --git a/Webzine.WebApplication/Controllers/RechercheController.cs b/Webzine.WebApplication/Controllers/RechercheController.cs index 2d5c4b9..be5b50f 100644 --- a/Webzine.WebApplication/Controllers/RechercheController.cs +++ b/Webzine.WebApplication/Controllers/RechercheController.cs @@ -9,12 +9,21 @@ namespace Webzine.WebApplication.Controllers using Webzine.Repository.Contracts; using Webzine.WebApplication.ViewModels.Recherche; + /// + /// Controller de la page de recherche d'artistes et de titres. + /// public class RechercheController : Controller { private readonly ILogger logger; private readonly ITitreRepository titreRepository; private readonly IArtisteRepository artisteRepository; + /// + /// Constructeur du controller de la page de recherche d'artistes et de titres. + /// + /// Le logger pour enregistrer les événements. + /// Le repository pour gérer les opérations sur les titres. + /// Le repository pour gérer les opérations sur les artistes. public RechercheController( ILogger logger, ITitreRepository titreRepository, @@ -29,7 +38,7 @@ namespace Webzine.WebApplication.Controllers /// Affichage de la page Recherche depuis le header de l'app. /// /// Nom d'artiste ou de titre. - /// Page de recherche avec les rsultats. + /// Page de recherche avec les r�sultats. public IActionResult Index(string mot) { // Logger la recherche. @@ -41,7 +50,7 @@ namespace Webzine.WebApplication.Controllers // Recherche des artistes. var artistes = this.artisteRepository.Search(mot); - // Paramtres a retourner la vue. + // Param�tres a retourner � la vue. var vm = new RechercheIndexViewModel { Mot = mot, diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index 01b1239..60c3ae0 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -82,7 +82,7 @@ namespace Webzine.WebApplication.Controllers /// /// Nom du style musical. /// Vue contenant la liste filtree. - [HttpGet("style/{style}")] + [HttpGet("style/{style}")] // TODO pas de route écrite en dur dans le controller public IActionResult Style(string style) { this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style); diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 916d86e..701b4ca 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -2,10 +2,8 @@ #pragma warning disable SA1200 using Microsoft.EntityFrameworkCore; - using NLog; using NLog.Web; - using Webzine.EntitiesContext; using Webzine.Entity; using Webzine.Entity.Fixtures; From 19b920ba4ea6d4039a6ffaf5d28a64727dc59e0b Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Tue, 31 Mar 2026 14:00:28 +0200 Subject: [PATCH 04/12] #146 Rerun dotnet format. --- Webzine.WebApplication/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 701b4ca..916d86e 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -2,8 +2,10 @@ #pragma warning disable SA1200 using Microsoft.EntityFrameworkCore; + using NLog; using NLog.Web; + using Webzine.EntitiesContext; using Webzine.Entity; using Webzine.Entity.Fixtures; From 03cc02b6f263a819285da73c6ae3800eb99d661e Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Wed, 1 Apr 2026 11:43:01 +0200 Subject: [PATCH 05/12] =?UTF-8?q?#175=20Correction=20des=20repository=20:?= =?UTF-8?q?=20=20First=20remplac=C3=A9=20par=20FirstOrDefault.=20Ajout=20d?= =?UTF-8?q?e=20la=20documentation=20manquante.=20Les=20return=20Model()=20?= =?UTF-8?q?vides=20sont=20supprim=C3=A9s.=20La=20gestion=20d'erreurs=20est?= =?UTF-8?q?=20optimis=C3=A9e.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IArtisteRepository.cs | 2 +- .../ICommentaireRepository.cs | 29 +++++++++++++++ Webzine.Repository/DbArtisteRepository.cs | 17 ++------- Webzine.Repository/DbCommentaireRepository.cs | 35 ++----------------- Webzine.Repository/DbEntityRepository.cs | 7 ++++ Webzine.Repository/DbStyleRepository.cs | 17 ++------- Webzine.Repository/DbTitreRepository.cs | 6 ---- Webzine.Repository/LocalArtisteRepository.cs | 13 +++---- .../LocalCommentaireRepository.cs | 33 ++--------------- Webzine.Repository/LocalStyleRepository.cs | 3 +- Webzine.Repository/LocalTitreRepository.cs | 2 +- 11 files changed, 54 insertions(+), 110 deletions(-) diff --git a/Webzine.Repository.Contracts/IArtisteRepository.cs b/Webzine.Repository.Contracts/IArtisteRepository.cs index 3c873c9..4eef62b 100644 --- a/Webzine.Repository.Contracts/IArtisteRepository.cs +++ b/Webzine.Repository.Contracts/IArtisteRepository.cs @@ -23,7 +23,7 @@ namespace Webzine.Repository.Contracts /// Récupère un artiste par son identifiant unique. Si aucun artiste n'est trouvé, retourne null. /// /// L'identifiant de l'artiste. - /// + /// L'artiste trouvé ou null. Artiste Find(int id); /// diff --git a/Webzine.Repository.Contracts/ICommentaireRepository.cs b/Webzine.Repository.Contracts/ICommentaireRepository.cs index 3529d83..bcd07d2 100644 --- a/Webzine.Repository.Contracts/ICommentaireRepository.cs +++ b/Webzine.Repository.Contracts/ICommentaireRepository.cs @@ -2,14 +2,43 @@ namespace Webzine.Repository.Contracts { using Webzine.Entity; + /// + /// Interface de repository pour les commentaires. + /// public interface ICommentaireRepository { + /// + /// Ajoute un commentaire à la source de données. + /// + /// Commentaire à ajouter. void Add(Commentaire commentaire); + /// + /// Supprime un commentaire de la source de données. + /// + /// Commentaire à supprimer. void Delete(Commentaire commentaire); + /// + /// Trouve un commentaire par son ID. + /// + /// ID du commentaire à trouver. + /// Le commentaire trouvé, ou null si non trouvé. Commentaire Find(int id); + /// + /// Retourne tous les commentaires de la source de données. + /// + /// Une collection de commentaires. IEnumerable FindAll(); + + /// + /// Retourne une collection de commentaires paginée à partir de la source de données. + /// + /// Le nombre de commentaires à ignorer avant de commencer à + /// récupérer les commentaires. + /// Le nombre maximum de commentaires à récupérer. + /// Une collection de commentaires paginée. + IEnumerable Paginate(int offset, int limit); } } \ No newline at end of file diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index d34628e..f1d5856 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -13,7 +13,6 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. // TODO commentaire faux. /// public class DbArtisteRepository : IArtisteRepository { @@ -23,8 +22,8 @@ namespace Webzine.Repository /// /// Initializes a new instance of the class. /// - /// Le contexte de base de données à utiliser pour accéder aux entités et effectuer des opérations de - /// persistance. Ne peut pas être null. + /// Le contexte de base de données à utiliser pour accéder aux entités et effectuer des opérations de persistance. + /// Le service de journalisation. public DbArtisteRepository(WebzineDbContext context, ILogger logger) { this.logger = logger; @@ -56,11 +55,6 @@ namespace Webzine.Repository { try { - if (artiste == null) - { - throw new ArgumentNullException(nameof(artiste), "L'artiste à supprimer ne peut pas être null."); - } - this.context.Artistes.Remove(artiste); this.context.SaveChanges(); this.logger.LogDebug("L'artiste {IdArtiste} a bien été supprimé", artiste.IdArtiste); @@ -125,18 +119,13 @@ namespace Webzine.Repository catch (Exception ex) { this.logger.LogError(ex, "Erreur lors de la récupération de tous les artistes."); - return Enumerable.Empty(); // Retourne une liste vide au lieu de faire crash l'UI + throw; } } /// public void Update(Artiste artiste) { - if (artiste == null) - { - throw new ArgumentNullException(nameof(artiste)); - } - try { this.context.Artistes.Update(artiste); diff --git a/Webzine.Repository/DbCommentaireRepository.cs b/Webzine.Repository/DbCommentaireRepository.cs index bfc5727..0c41ffd 100644 --- a/Webzine.Repository/DbCommentaireRepository.cs +++ b/Webzine.Repository/DbCommentaireRepository.cs @@ -16,10 +16,9 @@ public class DbCommentaireRepository : ICommentaireRepository private readonly WebzineDbContext context; /// - /// Initializes a new instance of the class. /// Initialisation de . /// - /// Le service de journalisation injecté pour suivre les opérations du repository. + /// Le service de journalisation. /// Le contexte de base de données injecté. public DbCommentaireRepository(ILogger logger, WebzineDbContext context) { @@ -33,7 +32,6 @@ public class DbCommentaireRepository : ICommentaireRepository { try { - this.logger.LogDebug("Ajout d'un nouveau commentaire de l'auteur : {Auteur}", commentaire.Auteur); this.context.Commentaires.Add(commentaire); this.context.SaveChanges(); this.logger.LogDebug("Commentaire ajouté avec l'id : {Id}", commentaire.IdCommentaire); @@ -55,11 +53,6 @@ public class DbCommentaireRepository : ICommentaireRepository { try { - if (commentaire == null) - { - throw new ArgumentNullException(nameof(commentaire), "Le commentaire à supprimer ne peut pas être null."); - } - this.context.Commentaires.Remove(commentaire); this.context.SaveChanges(); this.logger.LogDebug("Le commentaire {IdCommentaire} a bien été supprimé", commentaire.IdCommentaire); @@ -76,14 +69,6 @@ public class DbCommentaireRepository : ICommentaireRepository } } - /// - public int Count() - { - var count = this.context.Commentaires.Count(); - this.logger.LogDebug("Compte total des commentaires : {Count}", count); - return count; - } - /// public Commentaire Find(int idCommentaire) { @@ -98,8 +83,6 @@ public class DbCommentaireRepository : ICommentaireRepository /// public IEnumerable FindAll() { - this.logger.LogDebug("Récupération de tous les commentaires"); - var commentaires = this.context.Commentaires .Include(c => c.Titre) .OrderByDescending(c => c.DateCreation) @@ -110,7 +93,7 @@ public class DbCommentaireRepository : ICommentaireRepository } /// - public IEnumerable FindCommentaires(int offset, int limit) + public IEnumerable Paginate(int offset, int limit) { this.logger.LogDebug("Recherche paginée des commentaires (offset : {Offset}, limit : {Limit})", offset, limit); @@ -124,18 +107,4 @@ public class DbCommentaireRepository : ICommentaireRepository this.logger.LogDebug("{Count} commentaires trouvés pour cette page", commentaires.Count); return commentaires; } - - /// - public IEnumerable FindByIdTitre(int idTitre) - { - this.logger.LogDebug("Recherche des commentaires pour le titre ID : {IdTitre}", idTitre); - - var commentaires = this.context.Commentaires - .Where(c => c.Titre.IdTitre == idTitre) - .OrderByDescending(c => c.DateCreation) - .ToList(); - - this.logger.LogDebug($"{commentaires.Count} commentaires trouvés pour l'ID de titre : {idTitre}"); - return commentaires; - } } \ No newline at end of file diff --git a/Webzine.Repository/DbEntityRepository.cs b/Webzine.Repository/DbEntityRepository.cs index 1558cc6..9368fb6 100644 --- a/Webzine.Repository/DbEntityRepository.cs +++ b/Webzine.Repository/DbEntityRepository.cs @@ -8,10 +8,17 @@ namespace Webzine.Repository using Webzine.Entity; using Webzine.Entity.Fixtures; + /// + /// Classe de repository pour les entités de la base de données. + /// public class DbEntityRepository { private readonly WebzineDbContext context; + /// + /// Constructeur de DbEntityRepository. + /// + /// DB context. public DbEntityRepository(WebzineDbContext context) { this.context = context; diff --git a/Webzine.Repository/DbStyleRepository.cs b/Webzine.Repository/DbStyleRepository.cs index 4f5c20c..452b312 100644 --- a/Webzine.Repository/DbStyleRepository.cs +++ b/Webzine.Repository/DbStyleRepository.cs @@ -93,13 +93,6 @@ public class DbStyleRepository : IStyleRepository { this.logger.LogDebug("Recherche du style avec l'ID: {Id}", id); - if (id <= 0) // TODO à supprimer, c'est au controller de vérifier la validité de l'id - { - this.logger.LogWarning("Tentative de recherche d'un style avec un Id invalide: {Id}", id); - return new Style(); // TODO pas de retour d'objet vide - } - - this.logger.LogDebug("Préparation de la requête avec inclusion des titres"); var style = this.context.Styles .Include(s => s.Titres) .FirstOrDefault(s => s.IdStyle == id); @@ -107,13 +100,10 @@ public class DbStyleRepository : IStyleRepository if (style == null) { this.logger.LogWarning("Style avec l'ID {Id} non trouvé", id); - style = new Style(); - } - else - { - this.logger.LogDebug("Style trouvé: {Libelle}", style.Libelle); + return null; } + this.logger.LogDebug("Style trouvé: {Libelle}", style.Libelle); return style; } catch (Exception ex) @@ -151,7 +141,6 @@ public class DbStyleRepository : IStyleRepository try { this.logger.LogInformation("Mise à jour du style avec l'ID: {IdStyle}", style.IdStyle); - this.logger.LogDebug("Recherche du style en base de données"); var existingStyle = this.context.Styles.Find(style.IdStyle); if (existingStyle == null) @@ -160,8 +149,6 @@ public class DbStyleRepository : IStyleRepository throw new InvalidOperationException($"Style avec l'ID {style.IdStyle} non trouvé."); } - // Update properties - this.logger.LogDebug("Style trouvé, mise à jour des propriétés"); existingStyle.Libelle = style.Libelle; this.context.SaveChanges(); diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index 9390c15..0675c33 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -159,20 +159,14 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Incrémentation du nombre de likes pour le titre ID: {IdTitre}", titre.IdTitre); - this.logger.LogDebug("Recherche du titre en base de données"); var existingTitre = this.context.Titres.Find(titre.IdTitre); if (existingTitre != null) { - this.logger.LogDebug("Titre trouvé, incrémentation du compteur de likes"); existingTitre.NbLikes++; this.context.SaveChanges(); this.logger.LogDebug("Nouveau nombre de likes: {NbLikes}", existingTitre.NbLikes); } - else - { - this.logger.LogWarning("Titre avec l'ID {IdTitre} non trouvé pour l'incrémentation des likes", titre.IdTitre); - } } catch (DbUpdateException ex) { diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index a65fe44..8a4f51c 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -10,22 +10,21 @@ namespace Webzine.Repository using Webzine.Repository.Contracts; /// - /// Initialise une classe qui implémente l'interface pour gérer les opérations de base de données liées aux artistes. - /// Utilise en injection de dépendances. // TODO faux. + /// Initialise une classe qui implémente l'interface . + /// Gère les opérations liées aux artistes en utilisant une source de données locale (en mémoire). /// public class LocalArtisteRepository : IArtisteRepository { private readonly ILogger logger; - // private readonly List artistes; // TODO code mort private readonly InMemoryDataStore dataStore; /// /// Initializes a new instance of the class. /// Est liéee à une liste d'artistes en local et utilise un logger pour enregistrer les opérations effectuées sur les artistes. /// - /// La liste des artistes à initialiser. Ne peut pas être null. // TODO pas le bon paramètre /// Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null. + /// Le magasin de données en mémoire. public LocalArtisteRepository(InMemoryDataStore dataStore, ILogger logger) { this.logger = logger; @@ -49,11 +48,7 @@ namespace Webzine.Repository /// public Artiste Find(int id) { - var artiste = this.dataStore.Artistes.First(a => a.IdArtiste == id); - if (artiste == null) - { - return new Artiste(); // TODO ne pas retourner un objet vide, FirstOrDefault et gérer le null dans le controller - } + var artiste = this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id); return artiste; } diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index a0b1da3..8f71958 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -15,7 +15,6 @@ namespace Webzine.Repository /// /// Initialise une classe qui implémente l'interface pour gérer les opérations liées aux commentaires. - /// Utilise en injection de dépendances. /// public class LocalCommentaireRepository : ICommentaireRepository { @@ -25,7 +24,7 @@ namespace Webzine.Repository /// /// Initializes a new instance of the class. /// Initialise une nouvelle instance du . - /// Est liée à un magasin de données en mémoire et utilise un logger pour enregistrer les opérations. + /// Gère les opérations liées aux commentaires en utilisant une source de données locale (en mémoire). /// /// Le magasin de données en mémoire. Ne peut pas être null. /// Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null. @@ -47,22 +46,10 @@ namespace Webzine.Repository throw new NotSupportedException("Mode Local"); } - /// - public int Count() - { - return this.dataStore.Commentaires.Count; - } - /// public Commentaire Find(int idCommentaire) { - var commentaire = this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire); - if (commentaire == null) - { - return new Commentaire(); - } - - return commentaire; + return this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire); } /// @@ -74,27 +61,13 @@ namespace Webzine.Repository } /// - public IEnumerable FindCommentaires(int offset, int limit) + public IEnumerable Paginate(int offset, int limit) { - if (offset < 0 || limit <= 0) - { - return Enumerable.Empty(); - } - return this.dataStore.Commentaires .OrderByDescending(c => c.DateCreation) .Skip(offset) .Take(limit) .ToList(); } - - /// - public IEnumerable FindByIdTitre(int idTitre) - { - return this.dataStore.Commentaires - .Where(c => c.Titre != null && c.Titre.IdTitre == idTitre) - .OrderByDescending(c => c.DateCreation) - .ToList(); - } } } \ No newline at end of file diff --git a/Webzine.Repository/LocalStyleRepository.cs b/Webzine.Repository/LocalStyleRepository.cs index 0b4d16c..76d37dc 100644 --- a/Webzine.Repository/LocalStyleRepository.cs +++ b/Webzine.Repository/LocalStyleRepository.cs @@ -17,9 +17,10 @@ public class LocalStyleRepository : IStyleRepository /// /// Initializes a new instance of the class. + /// Gère les opérations liées aux styles en utilisant une source de données locale (en mémoire). /// /// Le service de journalisation injecté pour suivre les opérations du repository. - /// La liste de styles à utiliser comme source de données pour le repository. + /// Les données en mémoire. public LocalStyleRepository(ILogger logger, InMemoryDataStore dataStore) { this.logger = logger; diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index bc1e488..a970bf9 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -78,7 +78,7 @@ public class LocalTitreRepository : ITitreRepository public Titre Find(int idTitre) { return this.dataStore.Titres - .First(t => t.IdTitre == idTitre); + .FirstOrDefault(t => t.IdTitre == idTitre); } /// From 286397cb9e641556e4e2c22c484a4d3163c4d9f8 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Wed, 1 Apr 2026 15:26:20 +0200 Subject: [PATCH 06/12] =?UTF-8?q?#146=20Erreur=20de=20rebase=20supprim?= =?UTF-8?q?=C3=A9es=20(lignes=20dupliqu=C3=A9es.=20Ajout=20de=20AsNoTracki?= =?UTF-8?q?ng=20pour=20toutes=20les=20op=C3=A9rations=20de=20READ=20sur=20?= =?UTF-8?q?la=20bdd.=20Modification=20de=20la=20m=C3=A9thode=20Count().?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IArtisteRepository.cs | 4 +-- Webzine.Repository/DbArtisteRepository.cs | 5 ++- Webzine.Repository/DbCommentaireRepository.cs | 2 ++ Webzine.Repository/DbStyleRepository.cs | 2 ++ Webzine.Repository/DbTitreRepository.cs | 21 +++--------- Webzine.Repository/LocalArtisteRepository.cs | 1 - .../LocalCommentaireRepository.cs | 1 - Webzine.Repository/LocalTitreRepository.cs | 32 +++++++++++++++---- 8 files changed, 40 insertions(+), 28 deletions(-) diff --git a/Webzine.Repository.Contracts/IArtisteRepository.cs b/Webzine.Repository.Contracts/IArtisteRepository.cs index 4eef62b..936e694 100644 --- a/Webzine.Repository.Contracts/IArtisteRepository.cs +++ b/Webzine.Repository.Contracts/IArtisteRepository.cs @@ -3,8 +3,8 @@ namespace Webzine.Repository.Contracts using Webzine.Entity; /// - /// Défini une interface pour gérer les opérations de base de données liées aux artistes. - /// // TODO interface n'est pas que liée à la bdd, elle est aussi utilisée pour la gestion en mémoire + /// Défini une interface pour gérer les opérations des artistes dans la source de données. + /// public interface IArtisteRepository { /// diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index f1d5856..6d34837 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -112,7 +112,10 @@ namespace Webzine.Repository try { // .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture - var artistes = this.context.Artistes.AsNoTracking().Include(t => t.Titres).ToList(); + var artistes = this.context.Artistes + .AsNoTracking() + .Include(t => t.Titres) + .ToList(); this.logger.LogDebug("{Count} artistes récupérés de la base.", artistes.Count); return artistes; } diff --git a/Webzine.Repository/DbCommentaireRepository.cs b/Webzine.Repository/DbCommentaireRepository.cs index 0c41ffd..b5696ec 100644 --- a/Webzine.Repository/DbCommentaireRepository.cs +++ b/Webzine.Repository/DbCommentaireRepository.cs @@ -84,6 +84,7 @@ public class DbCommentaireRepository : ICommentaireRepository public IEnumerable FindAll() { var commentaires = this.context.Commentaires + .AsNoTracking() .Include(c => c.Titre) .OrderByDescending(c => c.DateCreation) .ToList(); @@ -98,6 +99,7 @@ public class DbCommentaireRepository : ICommentaireRepository this.logger.LogDebug("Recherche paginée des commentaires (offset : {Offset}, limit : {Limit})", offset, limit); var commentaires = this.context.Commentaires + .AsNoTracking() .Include(c => c.Titre) .OrderByDescending(c => c.DateCreation) .Skip(offset) diff --git a/Webzine.Repository/DbStyleRepository.cs b/Webzine.Repository/DbStyleRepository.cs index 452b312..9e69837 100644 --- a/Webzine.Repository/DbStyleRepository.cs +++ b/Webzine.Repository/DbStyleRepository.cs @@ -94,6 +94,7 @@ public class DbStyleRepository : IStyleRepository this.logger.LogDebug("Recherche du style avec l'ID: {Id}", id); var style = this.context.Styles + .AsNoTracking() .Include(s => s.Titres) .FirstOrDefault(s => s.IdStyle == id); @@ -122,6 +123,7 @@ public class DbStyleRepository : IStyleRepository this.logger.LogDebug("Tri des styles par libellé"); var styles = this.context.Styles + .AsNoTracking() .OrderBy(s => s.Libelle) .ToList(); diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index 0675c33..5ae3c9a 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -33,7 +33,6 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Ajout d'un nouveau titre: {Libelle}", titre.Libelle); - this.logger.LogDebug("Début de l'ajout du titre en base de données"); // TODO trop de logs this.context.Titres.Add(titre); this.context.SaveChanges(); @@ -57,8 +56,7 @@ public class DbTitreRepository : ITitreRepository { try { - this.logger.LogDebug("Comptage des titres en base de données"); - var count = this.context.Titres.Count(); + var count = Enumerable.Count(this.context.Titres); this.logger.LogDebug("Nombre total de titres: {Count}", count); return count; } @@ -75,7 +73,6 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Suppression du titre avec l'ID: {IdTitre}", titre.IdTitre); - this.logger.LogDebug("Début de la suppression du titre en base de données"); this.context.Titres.Remove(titre); this.context.SaveChanges(); @@ -100,7 +97,6 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogDebug("Recherche des titres avec offset: {Offset}, limit: {Limit}", offset, limit); - this.logger.LogDebug("Préparation de la requête avec les inclusions Artiste et Styles"); var titres = this.context.Titres .Include(t => t.Artiste) @@ -108,6 +104,7 @@ public class DbTitreRepository : ITitreRepository .OrderBy(t => t.Libelle) .Skip(offset) .Take(limit) + .AsNoTracking() .ToList(); this.logger.LogDebug("{Count} titres trouvés", titres.Count); @@ -126,12 +123,10 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Incrémentation du nombre de lectures pour le titre ID: {IdTitre}", titre.IdTitre); - this.logger.LogDebug("Recherche du titre en base de données"); var existingTitre = this.context.Titres.Find(titre.IdTitre); if (existingTitre != null) { - this.logger.LogDebug("Titre trouvé, incrémentation du compteur de lectures"); existingTitre.NbLectures++; this.context.SaveChanges(); this.logger.LogDebug("Nouveau nombre de lectures: {NbLectures}", existingTitre.NbLectures); @@ -186,16 +181,13 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Mise à jour du titre avec l'ID: {IdTitre}", titre.IdTitre); - this.logger.LogDebug("Début de la mise à jour du titre en base de données"); var existingTitre = this.context.Titres.Find(titre.IdTitre); if (existingTitre != null) { - this.logger.LogDebug("Titre trouvé, mise à jour des propriétés"); this.context.Entry(existingTitre).CurrentValues.SetValues(titre); - // Handle many-to-many relationships - this.logger.LogDebug("Mise à jour des relations many-to-many (Styles)"); + // Relation many-to-many this.context.Entry(existingTitre).Collection(t => t.Styles).Load(); existingTitre.Styles.Clear(); foreach (var style in titre.Styles) @@ -230,7 +222,6 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Recherche des titres avec le mot-clé: {Mot}", mot); - this.logger.LogDebug("Préparation de la requête de recherche avec les inclusions"); var titres = this.context.Titres .Include(t => t.Artiste) @@ -282,14 +273,12 @@ public class DbTitreRepository : ITitreRepository { try { - this.logger.LogDebug("Récupération de tous les titres"); // TODO trop de logs - this.logger.LogDebug("Préparation de la requête avec les inclusions Artiste et Styles"); - var titres = this.context.Titres .Include(t => t.Artiste) .Include(t => t.Styles) .Include(t => t.Commentaires) .OrderBy(t => t.Libelle) + .AsNoTracking() .ToList(); this.logger.LogDebug("{Count} titres récupérés", titres.Count); @@ -308,13 +297,13 @@ public class DbTitreRepository : ITitreRepository try { this.logger.LogInformation("Recherche des titres par style: {Libelle}", libelle); - this.logger.LogDebug("Préparation de la requête de recherche par style"); var titres = this.context.Titres .Include(t => t.Artiste) .Include(t => t.Styles) .Where(t => t.Styles.Any(s => s.Libelle.ToLower() == libelle.ToLower())) .OrderBy(t => t.Libelle) + .AsNoTracking() .ToList(); this.logger.LogDebug("{Count} titres trouvés pour le style '{Libelle}'", titres.Count, libelle); diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index ebab75c..8a4f51c 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -37,7 +37,6 @@ namespace Webzine.Repository public void Add(Artiste artiste) { throw new NotSupportedException("Mode Local"); // TODO à implémenter - throw new NotSupportedException("Mode Local"); // TODO à implémenter } /// diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index 8f71958..7096f49 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -22,7 +22,6 @@ namespace Webzine.Repository private readonly InMemoryDataStore dataStore; /// - /// Initializes a new instance of the class. /// Initialise une nouvelle instance du . /// Gère les opérations liées aux commentaires en utilisant une source de données locale (en mémoire). /// diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index a970bf9..5c5199b 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -34,10 +34,8 @@ public class LocalTitreRepository : ITitreRepository /// public int Count() { - var count = this.dataStore.Titres.Count(); // TODO une seule ligne, et attention car les deux méthodes s'appelent pareil, - - // il faut faire attention à ne pas confondre avec la méthode Count() de l'interface ITitreRepository - return count; + // On appelle directement LINQ count pour ne pas confondre avec la méthode Count() de l'interface ITitreRepository + return Enumerable.Count(this.dataStore.Titres); } /// @@ -58,20 +56,40 @@ public class LocalTitreRepository : ITitreRepository /// public void IncrementNbLectures(Titre titre) { - titre.NbLectures++; + var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre); + if (stored == null) + { + this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour incrémenter le nombre de lectures.", titre.IdTitre); + return; + } + + stored.NbLectures++; } /// public void IncrementNbLikes(Titre titre) { - titre.NbLikes++; // TODO rien n'est enregistré + var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre); + if (stored == null) + { + this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour incrémenter le nombre de likes.", titre.IdTitre); + return; + } + + stored.NbLikes++; } /// public IEnumerable Search(string mot) { + if (string.IsNullOrWhiteSpace(mot)) + { + return Enumerable.Empty(); + } + return this.dataStore.Titres - .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); // TODO attention au null, et à la casse, et à l'indexation pour les performances + .Where(t => t.Libelle.ToLower().Contains(mot.ToLower())) + .ToList(); } /// From afc9f1bdb479dbfab4ce1a467b983e1d25924e14 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Wed, 1 Apr 2026 16:48:18 +0200 Subject: [PATCH 07/12] =?UTF-8?q?#184=20Impl=C3=A9mentation=20des=20m?= =?UTF-8?q?=C3=A9thodes=20des=20repo=20en=20local.=20Suprression=20des=20e?= =?UTF-8?q?xceptions=20de=20non=20implementation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.Repository/LocalArtisteRepository.cs | 20 ++++++++++++------- .../LocalCommentaireRepository.cs | 5 ++--- Webzine.Repository/LocalStyleRepository.cs | 16 +++++++++++---- Webzine.Repository/LocalTitreRepository.cs | 18 ++++++++++++++--- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index 8a4f51c..2824780 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -36,21 +36,19 @@ namespace Webzine.Repository /// public void Add(Artiste artiste) { - throw new NotSupportedException("Mode Local"); // TODO à implémenter + this.dataStore.Artistes.Add(artiste); } /// public void Delete(Artiste artiste) { - throw new NotSupportedException("Mode Local"); + this.dataStore.Artistes.Remove(artiste); } /// public Artiste Find(int id) { - var artiste = this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id); - - return artiste; + return this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id); } /// @@ -69,7 +67,6 @@ namespace Webzine.Repository } /// - /// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle. public IEnumerable FindAll() { return this.dataStore.Artistes; @@ -78,7 +75,16 @@ namespace Webzine.Repository /// public void Update(Artiste artiste) { - throw new NotSupportedException("Mode Local"); + var stored = this.dataStore.Artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste); + if (stored == null) + { + this.logger.LogWarning("L'artiste {Id} n'a pas été trouvé pour l'update.", artiste.IdArtiste); + return; + } + + stored.Nom = artiste.Nom; + stored.Biographie = artiste.Biographie; + stored.Titres = artiste.Titres; } /// diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index 7096f49..98eea4d 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -4,7 +4,6 @@ namespace Webzine.Repository { - using System; using System.Collections.Generic; using System.Linq; @@ -36,13 +35,13 @@ namespace Webzine.Repository /// public void Add(Commentaire commentaire) { - throw new NotSupportedException("Mode Local"); // TODO à implémenter + this.dataStore.Commentaires.Add(commentaire); } /// public void Delete(Commentaire commentaire) { - throw new NotSupportedException("Mode Local"); + this.dataStore.Commentaires.Remove(commentaire); } /// diff --git a/Webzine.Repository/LocalStyleRepository.cs b/Webzine.Repository/LocalStyleRepository.cs index 76d37dc..5bf5979 100644 --- a/Webzine.Repository/LocalStyleRepository.cs +++ b/Webzine.Repository/LocalStyleRepository.cs @@ -31,19 +31,19 @@ public class LocalStyleRepository : IStyleRepository /// public void Add(Style style) { - throw new NotSupportedException("Mode local"); + this.dataStore.Styles.Add(style); } /// public void Delete(Style style) { - throw new NotSupportedException("Mode local"); + this.dataStore.Styles.Remove(style); } /// public Style Find(int id) { - return this.dataStore.Styles.Find(s => s.IdStyle == id); + return this.dataStore.Styles.SingleOrDefault(s => s.IdStyle == id); } /// @@ -55,6 +55,14 @@ public class LocalStyleRepository : IStyleRepository /// public void Update(Style style) { - throw new NotSupportedException("Mode local"); + var stored = this.dataStore.Styles.FirstOrDefault(s => s.IdStyle == style.IdStyle); + if (stored == null) + { + this.logger.LogWarning("Style with id {IdStyle} not found for update.", style.IdStyle); + return; + } + + stored.Libelle = style.Libelle; + stored.Titres = style.Titres; } } \ No newline at end of file diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index 5c5199b..b414a62 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -28,7 +28,7 @@ public class LocalTitreRepository : ITitreRepository /// public void Add(Titre titre) { - throw new NotSupportedException("Mode local"); + this.dataStore.Titres.Add(titre); } /// @@ -41,7 +41,7 @@ public class LocalTitreRepository : ITitreRepository /// public void Delete(Titre titre) { - throw new NotSupportedException("Mode Local"); + this.dataStore.Titres.Remove(titre); } /// @@ -115,6 +115,18 @@ public class LocalTitreRepository : ITitreRepository /// public void Update(Titre titre) { - throw new NotSupportedException("Mode local"); + var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre); + if (stored == null) + { + this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour mise à jour.", titre.IdTitre); + return; + } + + stored.Libelle = titre.Libelle; + stored.DateCreation = titre.DateCreation; + stored.NbLectures = titre.NbLectures; + stored.NbLikes = titre.NbLikes; + stored.IdArtiste = titre.IdArtiste; + stored.Styles = titre.Styles; } } \ No newline at end of file From e7b327a2ede9a7f4df6bb0c962802ee47584b12f Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Wed, 1 Apr 2026 17:01:00 +0200 Subject: [PATCH 08/12] =?UTF-8?q?#146=20Ajout=20de=20ModelState.IsValid=20?= =?UTF-8?q?pour=20les=20formulaires=20et=20op=C3=A9rations=20de=20suppress?= =?UTF-8?q?ion/edition.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Administration/Controllers/CommentaireController.cs | 8 ++++++++ .../Areas/Administration/Controllers/TitreController.cs | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/CommentaireController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/CommentaireController.cs index b954e14..1ca2c80 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/CommentaireController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/CommentaireController.cs @@ -5,6 +5,9 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers using Webzine.Repository.Contracts; using Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire; + /// + /// Contrôleur pour la gestion des commentaires dans l'administration du webzine. Ce contrôleur permet d'afficher la liste des commentaires, de supprimer un commentaire spécifique et de gérer les interactions liées aux commentaires dans l'interface d'administration. + /// [Area("Administration")] public class CommentaireController : Controller { @@ -80,6 +83,11 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers { var commentaire = this.commentaireRepository.Find(model.IdCommentaire); + if (!this.ModelState.IsValid) + { + return this.View(commentaire); + } + if (commentaire != null) { this.commentaireRepository.Delete(commentaire); diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/TitreController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/TitreController.cs index cab47aa..98efaf6 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/TitreController.cs @@ -154,6 +154,12 @@ public class TitreController : Controller public IActionResult Delete(AdminTitreDelete model) { var titre = this.titreRepository.Find(model.Id); + + if (!this.ModelState.IsValid) + { + return this.View(model); + } + if (titre != null) { this.titreRepository.Delete(titre); From e0beb20d3cad9303698e71dd0edb3104387af8bf Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Wed, 1 Apr 2026 17:11:38 +0200 Subject: [PATCH 09/12] #146 Modification de commentaires datant du jalon 1. --- .../Administration/Controllers/ArtisteController.cs | 4 +--- .../Controllers/ArtisteController.cs | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/ArtisteController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/ArtisteController.cs index e6ad7e5..6738804 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/ArtisteController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/ArtisteController.cs @@ -31,8 +31,7 @@ public class ArtisteController : Controller } /// - /// Affiche la liste des artistes. Pour l'instant, les artistes sont générés à partir de noms prédéfinis via la méthode SeedArtisteByName de la classe ArtisteFactory. - /// Chaque artiste est ensuite ajouté à une liste d'artistes qui est passée à la vue. + /// Affiche la liste des artistes. /// /// Redirection. public IActionResult Index() @@ -163,7 +162,6 @@ public class ArtisteController : Controller this.artisteRepository.Delete(artiste); } - // 3. Redirect back to the list (or wherever you want them to go after) return this.RedirectToAction("Index"); } } \ No newline at end of file diff --git a/Webzine.WebApplication/Controllers/ArtisteController.cs b/Webzine.WebApplication/Controllers/ArtisteController.cs index a24bec9..965b402 100644 --- a/Webzine.WebApplication/Controllers/ArtisteController.cs +++ b/Webzine.WebApplication/Controllers/ArtisteController.cs @@ -5,6 +5,10 @@ using Webzine.Repository.Contracts; using Webzine.WebApplication.ViewModels.Artiste; + /// + /// Contrôleur pour la gestion des artistes dans l'administration du webzine. Ce contrôleur gère les opérations de création, modification, suppression et affichage des artistes dans l'interface d'administration du webzine. Chaque action du contrôleur prépare un ViewModel spécifique pour la vue correspondante, permettant ainsi une séparation claire entre la logique métier et la présentation des données. + /// + /// public class ArtisteController : Controller { // Injection du logger via le constructeur @@ -12,10 +16,10 @@ private readonly IArtisteRepository artisteRepository; /// - /// Initializes a new instance of the class. /// Initialise une nouvelle instance du . avec un service de journalisation injecté. /// /// Service de journalisation injecté pour enregistrer les événements et les erreurs. + /// Repository pour accéder aux données des artistes, injecté pour permettre les opérations de création, modification, suppression et affichage des artistes. public ArtisteController( ILogger logger, IArtisteRepository artisteRepository) @@ -26,7 +30,7 @@ } /// - /// Prend en paramètre le nom de l'artiste (ex: "fatal-bazooka"), utilise la factory pour trouver l'artiste correspondant, et affiche sa page dédiée. + /// Affiche la liste des artistes. /// /// Le nom de l'artiste à rechercher, formaté en kebab-case (ex: "fatal-bazooka"). /// La vue de l'artiste avec son ViewModel, ou une redirection vers l'accueil si le nom est vide, ou une erreur 404 si l'artiste n'est pas trouvé. @@ -41,14 +45,12 @@ return this.RedirectToAction("Index", "Accueil"); } - // On transforme "fatal-bazooka" en "Fatal Bazooka" pour la factory + // On transforme "fatal-bazooka" en "Fatal Bazooka" string nomPropre = System.Globalization.CultureInfo.CurrentCulture.TextInfo .ToTitleCase(nom.Replace("-", " ")); - // On appelle la factory pour obtenir l'artiste unique var artiste = this.artisteRepository.FindByName(nomPropre); - // Check if artiste was found if (artiste == null) { this.logger.LogWarning("Artiste non trouvé avec le nom : {NomArtiste}", nomPropre); From 0d23a30f57388db3a1c7a9c20efc7c363f149a79 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Thu, 2 Apr 2026 12:00:27 +0200 Subject: [PATCH 10/12] =?UTF-8?q?fix:=20supprimer=20la=20gestion=20du=20co?= =?UTF-8?q?de=20de=20sortie=20pour=20les=20probl=C3=A8mes=20de=20performan?= =?UTF-8?q?ce=20dans=20les=20v=C3=A9rifications=20des=20points=20de=20term?= =?UTF-8?q?inaison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/pr-endpoint-check.yml | 9 +-------- scripts/test-endpoints.sh | 5 +---- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index 1aba34b..9cd7435 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -74,7 +74,6 @@ jobs: run: | chmod +x scripts/test-endpoints.sh bash scripts/test-endpoints.sh http://localhost:5038 1000 2>&1 | tee /tmp/webzine_endpoint_output.txt - EXIT_CODE=${PIPESTATUS[0]} FAIL_COUNT=$(grep -cE "^\[ÉCHEC\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) SLOW_COUNT=$(grep -cE "^\[LENT\]" /tmp/webzine_endpoint_output.txt 2>/dev/null || echo 0) @@ -137,10 +136,4 @@ jobs: -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg body "$BODY" '{body: $body}')" \ - "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" - - - name: Fail job if performance issues detected - if: steps.perf_test.outputs.failed > 0 || steps.perf_test.outputs.slow > 0 - run: | - echo "❌ Job failed due to performance issues" - exit 1 \ No newline at end of file + "$GITEA_SERVER_URL/api/v1/repos/$REPO/issues/$PR_NUMBER/comments" \ No newline at end of file diff --git a/scripts/test-endpoints.sh b/scripts/test-endpoints.sh index 0c96983..4eb567e 100644 --- a/scripts/test-endpoints.sh +++ b/scripts/test-endpoints.sh @@ -221,7 +221,4 @@ cat >> "$RAPPORT_FICHIER" < Date: Thu, 2 Apr 2026 14:41:01 +0200 Subject: [PATCH 11/12] =?UTF-8?q?#146=20Les=20m=C3=A9thodes=20Find(id)=20d?= =?UTF-8?q?es=20repository=20utilisent=20SingleOrDefault.=20Les=20m=C3=A9t?= =?UTF-8?q?hodes=20find=20du=20repository=20sont=20utilis=C3=A9es=20dans?= =?UTF-8?q?=20les=20m=C3=A9thodes=20update=20au=20lieu=20de=20refaire=20un?= =?UTF-8?q?e=20requ=C3=AAte.=20Paginate=20est=20remplac=C3=A9=20par=20Find?= =?UTF-8?q?[Model]=20pour=20correspondre=20au=20cahier=20des=20charges.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICommentaireRepository.cs | 2 +- Webzine.Repository/DbArtisteRepository.cs | 19 ++++++---- Webzine.Repository/DbCommentaireRepository.cs | 35 +++++++++++-------- Webzine.Repository/DbStyleRepository.cs | 15 ++++---- Webzine.Repository/DbTitreRepository.cs | 22 +++++------- Webzine.Repository/LocalArtisteRepository.cs | 10 +++--- .../LocalCommentaireRepository.cs | 7 ++-- Webzine.Repository/LocalStyleRepository.cs | 8 ++--- Webzine.Repository/LocalTitreRepository.cs | 20 ++++++----- 9 files changed, 73 insertions(+), 65 deletions(-) diff --git a/Webzine.Repository.Contracts/ICommentaireRepository.cs b/Webzine.Repository.Contracts/ICommentaireRepository.cs index bcd07d2..c87fb9e 100644 --- a/Webzine.Repository.Contracts/ICommentaireRepository.cs +++ b/Webzine.Repository.Contracts/ICommentaireRepository.cs @@ -39,6 +39,6 @@ namespace Webzine.Repository.Contracts /// récupérer les commentaires. /// Le nombre maximum de commentaires à récupérer. /// Une collection de commentaires paginée. - IEnumerable Paginate(int offset, int limit); + IEnumerable FindCommentaires(int offset, int limit); } } \ No newline at end of file diff --git a/Webzine.Repository/DbArtisteRepository.cs b/Webzine.Repository/DbArtisteRepository.cs index 2c50cdc..01bc409 100644 --- a/Webzine.Repository/DbArtisteRepository.cs +++ b/Webzine.Repository/DbArtisteRepository.cs @@ -78,7 +78,7 @@ namespace Webzine.Repository { Artiste artiste = this.context.Artistes .Include(a => a.Titres) - .FirstOrDefault(a => a.IdArtiste == id); + .SingleOrDefault(a => a.IdArtiste == id); return artiste; } catch (Exception ex) @@ -112,11 +112,12 @@ namespace Webzine.Repository try { // .AsNoTracking() rend la requête beaucoup plus rapide pour de la lecture + // Pas besoin de faire un ToList() ici, car on retourne un IEnumerable et EF Core gère l'exécution différée de la requête. var artistes = this.context.Artistes .AsNoTracking() - .Include(t => t.Titres) - .ToList(); - this.logger.LogDebug("{Count} artistes récupérés de la base.", artistes.Count); + .Include(t => t.Titres); + + this.logger.LogDebug("La liste d'artistes a été récupérée de la base."); return artistes; } catch (Exception ex) @@ -131,6 +132,13 @@ namespace Webzine.Repository { try { + Artiste existingArtiste = this.Find(artiste.IdArtiste); // Vérifie que l'artiste existe avant de tenter de le mettre à jour + if (existingArtiste == null) + { + this.logger.LogWarning("L'artiste {Id} n'a pas été trouvé pour l'update.", artiste.IdArtiste); + throw new InvalidOperationException($"L'artiste avec l'ID {artiste.IdArtiste} n'a pas été trouvé pour la mise à jour."); + } + this.context.Artistes.Update(artiste); this.context.SaveChanges(); this.logger.LogDebug("Artiste {Id} ({Nom}) mis à jour avec succès.", artiste.IdArtiste, artiste.Nom); @@ -159,8 +167,7 @@ namespace Webzine.Repository var artiste = this.context.Artistes .Where(a => a.Nom.ToLower().Contains(mot.ToLower())) .Include(t => t.Titres) - .AsNoTracking() - .ToList(); + .AsNoTracking(); return artiste; } catch (Exception ex) diff --git a/Webzine.Repository/DbCommentaireRepository.cs b/Webzine.Repository/DbCommentaireRepository.cs index b5696ec..a101dfd 100644 --- a/Webzine.Repository/DbCommentaireRepository.cs +++ b/Webzine.Repository/DbCommentaireRepository.cs @@ -77,7 +77,7 @@ public class DbCommentaireRepository : ICommentaireRepository // On inclut le titre car il est souvent affiché avec le commentaire return this.context.Commentaires .Include(c => c.Titre) - .FirstOrDefault(c => c.IdCommentaire == idCommentaire); + .SingleOrDefault(c => c.IdCommentaire == idCommentaire); } /// @@ -86,27 +86,32 @@ public class DbCommentaireRepository : ICommentaireRepository var commentaires = this.context.Commentaires .AsNoTracking() .Include(c => c.Titre) - .OrderByDescending(c => c.DateCreation) - .ToList(); + .OrderByDescending(c => c.DateCreation); - this.logger.LogDebug("Nombre de commentaires trouvés : {Count}", commentaires.Count); + this.logger.LogDebug("La liste de commentaires a été récupérée."); return commentaires; } /// - public IEnumerable Paginate(int offset, int limit) + public IEnumerable FindCommentaires(int offset, int limit) { - this.logger.LogDebug("Recherche paginée des commentaires (offset : {Offset}, limit : {Limit})", offset, limit); + try + { + this.logger.LogDebug("Recherche paginée des commentaires (offset : {Offset}, limit : {Limit})", offset, limit); - var commentaires = this.context.Commentaires - .AsNoTracking() - .Include(c => c.Titre) - .OrderByDescending(c => c.DateCreation) - .Skip(offset) - .Take(limit) - .ToList(); + var commentaires = this.context.Commentaires + .AsNoTracking() + .Include(c => c.Titre) + .OrderByDescending(c => c.DateCreation) + .Skip(offset) + .Take(limit); - this.logger.LogDebug("{Count} commentaires trouvés pour cette page", commentaires.Count); - return commentaires; + return commentaires; + } + catch (Exception ex) + { + this.logger.LogError(ex, "Erreur lors de la pagination des commentaires (offset : {Offset}, limit : {Limit})", offset, limit); + throw new Exception("Une erreur est survenue lors de la pagination des commentaires.", ex); + } } } \ No newline at end of file diff --git a/Webzine.Repository/DbStyleRepository.cs b/Webzine.Repository/DbStyleRepository.cs index 7b8c0c7..0412a90 100644 --- a/Webzine.Repository/DbStyleRepository.cs +++ b/Webzine.Repository/DbStyleRepository.cs @@ -96,7 +96,7 @@ public class DbStyleRepository : IStyleRepository var style = this.context.Styles .AsNoTracking() .Include(s => s.Titres) - .FirstOrDefault(s => s.IdStyle == id); + .SingleOrDefault(s => s.IdStyle == id); if (style == null) { @@ -124,10 +124,9 @@ public class DbStyleRepository : IStyleRepository var styles = this.context.Styles .AsNoTracking() - .OrderBy(s => s.Libelle) - .ToList(); + .OrderBy(s => s.Libelle); - this.logger.LogDebug("{Count} styles récupérés", styles.Count); + this.logger.LogDebug("La liste de styles a été récupérée."); return styles; } catch (Exception ex) @@ -143,15 +142,15 @@ public class DbStyleRepository : IStyleRepository try { this.logger.LogInformation("Mise à jour du style avec l'ID: {IdStyle}", style.IdStyle); + Style existingStyle = this.Find(style.IdStyle); // Vérifie que le style existe avant de tenter de le mettre à jour - var existingStyle = this.context.Styles.Find(style.IdStyle); if (existingStyle == null) { - this.logger.LogWarning("Style avec l'ID {IdStyle} non trouvé pour la mise à jour", style.IdStyle); - throw new InvalidOperationException($"Style avec l'ID {style.IdStyle} non trouvé."); + this.logger.LogWarning("Style avec l'ID {IdStyle} non trouvé pour l'update.", style.IdStyle); + throw new InvalidOperationException($"Style avec l'ID {style.IdStyle} non trouvé pour la mise à jour."); } - existingStyle.Libelle = style.Libelle; + this.context.Styles.Update(style); this.context.SaveChanges(); this.logger.LogDebug("Style mis à jour avec succès: {IdStyle}", style.IdStyle); diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index 5ae3c9a..524f924 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -104,10 +104,9 @@ public class DbTitreRepository : ITitreRepository .OrderBy(t => t.Libelle) .Skip(offset) .Take(limit) - .AsNoTracking() - .ToList(); + .AsNoTracking(); - this.logger.LogDebug("{Count} titres trouvés", titres.Count); + this.logger.LogDebug("La liste de titres a été récupérée."); return titres; } catch (Exception ex) @@ -182,7 +181,7 @@ public class DbTitreRepository : ITitreRepository { this.logger.LogInformation("Mise à jour du titre avec l'ID: {IdTitre}", titre.IdTitre); - var existingTitre = this.context.Titres.Find(titre.IdTitre); + Titre existingTitre = this.Find(titre.IdTitre); if (existingTitre != null) { this.context.Entry(existingTitre).CurrentValues.SetValues(titre); @@ -228,10 +227,9 @@ public class DbTitreRepository : ITitreRepository .Include(t => t.Styles) .Where(t => t.Libelle.ToLower().Contains(mot.ToLower())) .OrderBy(t => t.Libelle) - .AsNoTracking() - .ToList(); + .AsNoTracking(); - this.logger.LogDebug("{Count} titres trouvés correspondant à '{Mot}'", titres.Count, mot); + this.logger.LogDebug("La liste de titres a été récupérée."); return titres; } catch (Exception ex) @@ -278,10 +276,9 @@ public class DbTitreRepository : ITitreRepository .Include(t => t.Styles) .Include(t => t.Commentaires) .OrderBy(t => t.Libelle) - .AsNoTracking() - .ToList(); + .AsNoTracking(); - this.logger.LogDebug("{Count} titres récupérés", titres.Count); + this.logger.LogDebug("La liste de titres a été récupérée avec FindAll."); return titres; } catch (Exception ex) @@ -303,10 +300,9 @@ public class DbTitreRepository : ITitreRepository .Include(t => t.Styles) .Where(t => t.Styles.Any(s => s.Libelle.ToLower() == libelle.ToLower())) .OrderBy(t => t.Libelle) - .AsNoTracking() - .ToList(); + .AsNoTracking(); - this.logger.LogDebug("{Count} titres trouvés pour le style '{Libelle}'", titres.Count, libelle); + this.logger.LogDebug("La liste de titres a été récupérée pour le style '{Libelle}'", libelle); return titres; } catch (Exception ex) diff --git a/Webzine.Repository/LocalArtisteRepository.cs b/Webzine.Repository/LocalArtisteRepository.cs index 1aa7137..402aca1 100644 --- a/Webzine.Repository/LocalArtisteRepository.cs +++ b/Webzine.Repository/LocalArtisteRepository.cs @@ -75,16 +75,16 @@ namespace Webzine.Repository /// public void Update(Artiste artiste) { - var stored = this.dataStore.Artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste); - if (stored == null) + Artiste existingArtiste = this.Find(artiste.IdArtiste); + if (existingArtiste == null) { this.logger.LogWarning("L'artiste {Id} n'a pas été trouvé pour l'update.", artiste.IdArtiste); return; } - stored.Nom = artiste.Nom; - stored.Biographie = artiste.Biographie; - stored.Titres = artiste.Titres; + existingArtiste.Nom = artiste.Nom; + existingArtiste.Biographie = artiste.Biographie; + existingArtiste.Titres = artiste.Titres; } /// diff --git a/Webzine.Repository/LocalCommentaireRepository.cs b/Webzine.Repository/LocalCommentaireRepository.cs index 98eea4d..4e2ad79 100644 --- a/Webzine.Repository/LocalCommentaireRepository.cs +++ b/Webzine.Repository/LocalCommentaireRepository.cs @@ -47,7 +47,7 @@ namespace Webzine.Repository /// public Commentaire Find(int idCommentaire) { - return this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire); + return this.dataStore.Commentaires.SingleOrDefault(c => c.IdCommentaire == idCommentaire); } /// @@ -59,13 +59,12 @@ namespace Webzine.Repository } /// - public IEnumerable Paginate(int offset, int limit) + public IEnumerable FindCommentaires(int offset, int limit) { return this.dataStore.Commentaires .OrderByDescending(c => c.DateCreation) .Skip(offset) - .Take(limit) - .ToList(); + .Take(limit); } } } \ No newline at end of file diff --git a/Webzine.Repository/LocalStyleRepository.cs b/Webzine.Repository/LocalStyleRepository.cs index 6fbcc41..ed26315 100644 --- a/Webzine.Repository/LocalStyleRepository.cs +++ b/Webzine.Repository/LocalStyleRepository.cs @@ -55,15 +55,15 @@ public class LocalStyleRepository : IStyleRepository /// public void Update(Style style) { - var stored = this.dataStore.Styles.FirstOrDefault(s => s.IdStyle == style.IdStyle); - if (stored == null) + Style existingStyle = this.Find(style.IdStyle); + if (existingStyle == null) { this.logger.LogWarning("Style with id {IdStyle} not found for update.", style.IdStyle); return; } - stored.Libelle = style.Libelle; - stored.Titres = style.Titres; + existingStyle.Libelle = style.Libelle; + existingStyle.Titres = style.Titres; } /// diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index b414a62..de237ef 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -96,7 +96,7 @@ public class LocalTitreRepository : ITitreRepository public Titre Find(int idTitre) { return this.dataStore.Titres - .FirstOrDefault(t => t.IdTitre == idTitre); + .SingleOrDefault(t => t.IdTitre == idTitre); } /// @@ -115,18 +115,20 @@ public class LocalTitreRepository : ITitreRepository /// public void Update(Titre titre) { - var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre); - if (stored == null) + // On trouve le titre stocké pour mettre à jour ses propriétés avec la méthode Find du repository + // pour éviter la duplication de code. + Titre existingTitre = this.Find(titre.IdTitre); + if (existingTitre == null) { this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour mise à jour.", titre.IdTitre); return; } - stored.Libelle = titre.Libelle; - stored.DateCreation = titre.DateCreation; - stored.NbLectures = titre.NbLectures; - stored.NbLikes = titre.NbLikes; - stored.IdArtiste = titre.IdArtiste; - stored.Styles = titre.Styles; + existingTitre.Libelle = titre.Libelle; + existingTitre.DateCreation = titre.DateCreation; + existingTitre.NbLectures = titre.NbLectures; + existingTitre.NbLikes = titre.NbLikes; + existingTitre.IdArtiste = titre.IdArtiste; + existingTitre.Styles = titre.Styles; } } \ No newline at end of file From 1a63f41de92790a40d7e29a094ace40837086565 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Thu, 2 Apr 2026 15:16:31 +0200 Subject: [PATCH 12/12] feat: renommer la cible de la console et ajuster le niveau de log pour Webzine.WebApplication --- Webzine.WebApplication/nlog.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Webzine.WebApplication/nlog.config b/Webzine.WebApplication/nlog.config index 1b64237..c2ba55e 100644 --- a/Webzine.WebApplication/nlog.config +++ b/Webzine.WebApplication/nlog.config @@ -22,13 +22,13 @@ layout="${longdate}|${level:uppercase=true}|${logger}|${message} ${exception:format=tostring}|${aspnet-request-url:whenEmpty=NoRequest}" /> - - +