From f193aa47e141861b04cca263da9a811efc743800 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Tue, 31 Mar 2026 13:53:42 +0200 Subject: [PATCH 01/25] 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/25] #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 a52c08ec326543d13f374dc2a65e3bcecb251f59 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 15:32:19 +0200 Subject: [PATCH 03/25] feat: incrementer le nombre de lectures et de likes dans TitreController --- Webzine.WebApplication/Controllers/TitreController.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index 01b1239..e4c0cd7 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -53,6 +53,8 @@ namespace Webzine.WebApplication.Controllers return this.RedirectToAction("Index"); } + this.titreRepository.IncrementNbLectures(titre); + var vm = new TitreDetail { Details = new TitreContent @@ -113,10 +115,11 @@ namespace Webzine.WebApplication.Controllers if (titre == null) { this.logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre); - return this.RedirectToAction("Index"); } - - titre.NbLikes++; + else + { + this.titreRepository.IncrementNbLikes(titre); + } return this.RedirectToAction("Details", new { id = model.IdTitre }); } From 7c373d081b33dc352ec79bb0055716ac8a2c1fad Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 16:53:34 +0200 Subject: [PATCH 04/25] =?UTF-8?q?feat:=20impl=C3=A9mentation=20TitreAdminS?= =?UTF-8?q?ervice=20pour=20la=20gestion=20des=20titres=20et=20ajout=20Titr?= =?UTF-8?q?eAdminMod=C3=A8le=20de=20commande?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ITitreAdminService.cs | 22 +++ .../Models/TitreAdminCommande.cs | 58 ++++++++ Webzine.Business/TitreAdminService.cs | 130 ++++++++++++++++++ Webzine.Business/Webzine.Business.csproj | 11 ++ Webzine.Repository/DbTitreRepository.cs | 27 +--- .../Controllers/TitreController.cs | 45 +++++- Webzine.WebApplication/Program.cs | 4 + .../Webzine.WebApplication.csproj | 2 + 8 files changed, 276 insertions(+), 23 deletions(-) create mode 100644 Webzine.Business.Contracts/ITitreAdminService.cs create mode 100644 Webzine.Business.Contracts/Models/TitreAdminCommande.cs create mode 100644 Webzine.Business/TitreAdminService.cs diff --git a/Webzine.Business.Contracts/ITitreAdminService.cs b/Webzine.Business.Contracts/ITitreAdminService.cs new file mode 100644 index 0000000..72f6a0a --- /dev/null +++ b/Webzine.Business.Contracts/ITitreAdminService.cs @@ -0,0 +1,22 @@ +namespace Webzine.Business.Contracts; + +using Webzine.Business.Contracts.Models; + +/// +/// Service responsable des opérations d'administration sur les titres. +/// Orchestre la résolution des dépendances (artiste, styles) et la persistance. +/// +public interface ITitreAdminService +{ + /// + /// Crée un nouveau titre à partir des données du formulaire d'administration. + /// + /// Les données saisies dans le formulaire de création. + void CreerTitre(TitreAdminCommande commande); + + /// + /// Met à jour un titre existant à partir des données du formulaire d'administration. + /// + /// Les données saisies dans le formulaire de modification. + void ModifierTitre(TitreAdminCommande commande); +} \ No newline at end of file diff --git a/Webzine.Business.Contracts/Models/TitreAdminCommande.cs b/Webzine.Business.Contracts/Models/TitreAdminCommande.cs new file mode 100644 index 0000000..b97c4c0 --- /dev/null +++ b/Webzine.Business.Contracts/Models/TitreAdminCommande.cs @@ -0,0 +1,58 @@ +namespace Webzine.Business.Contracts.Models; + +/// +/// Commande transportant les données métier d'un titre saisi en administration. +/// Ne contient pas les listes de sélection (celles-ci restent dans le ViewModel). +/// +public class TitreAdminCommande +{ + /// + /// Identifiant du titre (0 lors d'une création). + /// + public int Id { get; set; } + + /// + /// Identifiant de l'artiste sélectionné. + /// + public int IdArtiste { get; set; } + + /// + /// Libellé du titre. + /// + public string Libelle { get; set; } = string.Empty; + + /// + /// Nom de l'album. + /// + public string Album { get; set; } = string.Empty; + + /// + /// Texte de la chronique. + /// + public string Chronique { get; set; } = string.Empty; + + /// + /// Date de sortie du titre. + /// + public DateTime DateSortie { get; set; } + + /// + /// Durée en secondes. + /// + public int Duree { get; set; } + + /// + /// URL de la jaquette. + /// + public string UrlJaquette { get; set; } = string.Empty; + + /// + /// URL d'écoute. + /// + public string? UrlEcoute { get; set; } + + /// + /// Identifiants des styles sélectionnés. + /// + public List Styles { get; set; } = new (); +} \ No newline at end of file diff --git a/Webzine.Business/TitreAdminService.cs b/Webzine.Business/TitreAdminService.cs new file mode 100644 index 0000000..2357811 --- /dev/null +++ b/Webzine.Business/TitreAdminService.cs @@ -0,0 +1,130 @@ +namespace Webzine.Business; + +using Microsoft.Extensions.Logging; + +using Webzine.Business.Contracts; +using Webzine.Business.Contracts.Models; +using Webzine.Entity; +using Webzine.Repository.Contracts; + +/// +/// Implémentation de . +/// Orchestre la résolution des styles, la construction de l'entité +/// et la délégation au repository. +/// +public class TitreAdminService : ITitreAdminService +{ + private readonly ITitreRepository titreRepository; + private readonly IArtisteRepository artisteRepository; + private readonly IStyleRepository styleRepository; + private readonly ILogger logger; + + /// + /// Initializes a new instance of the class. + /// + /// Repository des titres. + /// Repository des artistes. + /// Repository des styles. + /// Service de journalisation. + public TitreAdminService( + ITitreRepository titreRepository, + IArtisteRepository artisteRepository, + IStyleRepository styleRepository, + ILogger logger) + { + this.titreRepository = titreRepository; + this.artisteRepository = artisteRepository; + this.styleRepository = styleRepository; + this.logger = logger; + } + + /// + public void CreerTitre(TitreAdminCommande commande) + { + this.logger.LogInformation( + "Création d'un nouveau titre '{Libelle}' pour l'artiste ID {IdArtiste}.", + commande.Libelle, + commande.IdArtiste); + + Artiste artiste = this.artisteRepository.Find(commande.IdArtiste); + List