From b407317e95e59f63b38668105d019e336cb65451 Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Thu, 5 Mar 2026 14:10:56 +0100 Subject: [PATCH 1/2] =?UTF-8?q?#21=20Cr=C3=A9ation=20d'un=20ArtisteFactory?= =?UTF-8?q?=20qui=20g=C3=A9n=C3=A8re=20des=20titres=20et=20deux=20albums?= =?UTF-8?q?=20par=20artiste.=20Le=20viewmod=C3=A8le=20est=20pass=C3=A9=20d?= =?UTF-8?q?ans=20la=20vue=20par=20le=20controleur.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.Entity/Fixtures/ArtisteFactory.cs | 54 ++++++++++++++ Webzine.Entity/Webzine.Entity.csproj | 1 + .../Controllers/AccueilController.cs | 9 +++ .../Controllers/ArtisteController.cs | 54 ++++++++++++++ .../ViewModels/ArtisteModel.cs | 17 +++++ .../Views/Artiste/Index.cshtml | 70 +++++++++++++++++++ .../Views/Shared/_Layout.cshtml | 2 +- .../Webzine.WebApplication.csproj.user | 5 +- 8 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 Webzine.Entity/Fixtures/ArtisteFactory.cs create mode 100644 Webzine.WebApplication/Controllers/ArtisteController.cs create mode 100644 Webzine.WebApplication/ViewModels/ArtisteModel.cs create mode 100644 Webzine.WebApplication/Views/Artiste/Index.cshtml diff --git a/Webzine.Entity/Fixtures/ArtisteFactory.cs b/Webzine.Entity/Fixtures/ArtisteFactory.cs new file mode 100644 index 0000000..4161e35 --- /dev/null +++ b/Webzine.Entity/Fixtures/ArtisteFactory.cs @@ -0,0 +1,54 @@ +using Bogus; + +namespace Webzine.Entity.Fixtures +{ + /// + /// Factory pour générer des artistes avec des titres associés, à l'aide de la bibliothèque Bogus. + /// + /// + public class ArtisteFactory + { + /// + /// Récupère un artiste par son nom, en générant des données fictives pour ses titres associés. + /// + /// + /// + public static Artiste FindByName(string nom) + { + // On définit nos albums "bouchonnés" + var albumsData = new[] + { + new { Nom = "Bohemian Rhapsody", Image = "https://upload.wikimedia.org/wikipedia/en/9/9f/Bohemian_Rhapsody.png" }, + new { Nom = "Born This Way", Image = "https://static.wikia.nocookie.net/ladygaga/images/2/2d/BornThisWay-DeluxeEdition.jpg/revision/latest/scale-to-width-down/3500?cb=20111120030308" } + }; + + var faker = new Bogus.Faker("fr"); + var tousLesTitres = new List(); + + // Pour chaque album, on génère un paquet de titres + foreach (var album in albumsData) + { + var nombreDeTitres = faker.Random.Number(3, 6); + + var titresDeLalbum = new Faker("fr") + .RuleFor(t => t.IdTitre, f => f.IndexFaker + 1 + tousLesTitres.Count) + .RuleFor(t => t.UrlJaquette, _ => album.Image) + .RuleFor(t => t.Album, _ => album.Nom) + .RuleFor(t => t.Duree, f => f.Random.Number(90, 180)) + .RuleFor(t => t.Libelle, f => f.Music.Genre() + " - " + f.Commerce.ProductName()) + .Generate(nombreDeTitres); + + tousLesTitres.AddRange(titresDeLalbum); + } + + // On crée l'artiste final + var artisteFaker = new Faker("fr") + .RuleFor(a => a.IdArtiste, f => f.IndexFaker + 1) + .RuleFor(a => a.Nom, _ => nom) + .RuleFor(a => a.Biographie, f => f.Lorem.Paragraphs(2)) + .RuleFor(a => a.Titres, _ => tousLesTitres); + + return artisteFaker.Generate(); + } + } +} \ No newline at end of file diff --git a/Webzine.Entity/Webzine.Entity.csproj b/Webzine.Entity/Webzine.Entity.csproj index 33c0658..06e46f1 100644 --- a/Webzine.Entity/Webzine.Entity.csproj +++ b/Webzine.Entity/Webzine.Entity.csproj @@ -7,6 +7,7 @@ + diff --git a/Webzine.WebApplication/Controllers/AccueilController.cs b/Webzine.WebApplication/Controllers/AccueilController.cs index 32e2e49..1602c40 100644 --- a/Webzine.WebApplication/Controllers/AccueilController.cs +++ b/Webzine.WebApplication/Controllers/AccueilController.cs @@ -5,9 +5,18 @@ namespace Webzine.WebApplication.Controllers { public class AccueilController : Controller { + // Injection du logger via le constructeur + private readonly ILogger _logger; + + public AccueilController(ILogger logger) + { + _logger = logger; + } + // GET: AccueilController public ActionResult Index() { + _logger.LogInformation("Arrivée sur la page d'accueil"); return View(); } diff --git a/Webzine.WebApplication/Controllers/ArtisteController.cs b/Webzine.WebApplication/Controllers/ArtisteController.cs new file mode 100644 index 0000000..0f26971 --- /dev/null +++ b/Webzine.WebApplication/Controllers/ArtisteController.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Mvc; +using Webzine.Entity.Fixtures; +using Webzine.WebApplication.ViewModels; + +namespace Webzine.WebApplication.Controllers +{ + public class ArtisteController : Controller + { + // Injection du logger via le constructeur + private readonly ILogger _logger; + + public ArtisteController(ILogger logger) + { + _logger = logger; + } + + /// + /// 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. + /// + /// + /// + [HttpGet("/artiste/{nom}")] + public IActionResult Index(string nom) + { + _logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom); + + if (string.IsNullOrEmpty(nom)) return RedirectToAction("Index", "Accueil"); + + // On transforme "fatal-bazooka" en "Fatal Bazooka" pour la factory + string nomPropre = System.Globalization.CultureInfo.CurrentCulture.TextInfo + .ToTitleCase(nom.Replace("-", " ")); + + // On appelle la factory pour obtenir l'artiste unique + var artiste = ArtisteFactory.FindByName(nomPropre); + + if (artiste == null) + { + _logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre); + return NotFound(); + } + + _logger.LogInformation("Artiste trouvé : {NomArtiste}", nom); + + // On remplit le ViewModel + var viewModel = new ArtisteModel + { + Artiste = artiste, + Titres = artiste.Titres + }; + + return View(viewModel); + } + } +} diff --git a/Webzine.WebApplication/ViewModels/ArtisteModel.cs b/Webzine.WebApplication/ViewModels/ArtisteModel.cs new file mode 100644 index 0000000..176623c --- /dev/null +++ b/Webzine.WebApplication/ViewModels/ArtisteModel.cs @@ -0,0 +1,17 @@ +using Webzine.Entity; + +namespace Webzine.WebApplication.ViewModels +{ + public class ArtisteModel + { + /// + /// Artiste dont on affiche les détails. + /// + public Artiste Artiste { get; set; } + + /// + /// Liste des titres de l'artiste. + /// + public List Titres { get; set; } + } +} diff --git a/Webzine.WebApplication/Views/Artiste/Index.cshtml b/Webzine.WebApplication/Views/Artiste/Index.cshtml new file mode 100644 index 0000000..2063243 --- /dev/null +++ b/Webzine.WebApplication/Views/Artiste/Index.cshtml @@ -0,0 +1,70 @@ +@model Webzine.WebApplication.ViewModels.ArtisteModel + +@{ + ViewData["Title"] = "Artiste"; +} + + +
+

@Model.Artiste.Nom

+ +
+ +

@Model.Artiste.Biographie

+ +

Albums

+
+ + @* On groupe les titres par nom d'album *@ + @{ + var albumsGroupes = Model.Titres + .OrderBy(t => t.Libelle) // Trie les titres par ordre alphabétique au sein de chaque groupe futur + .GroupBy(t => t.Album) // Groupe par nom d'album + .OrderBy(g => g.Key); // Trie les albums par ordre alphabétique (la clé du groupe) + } + + @foreach (var groupe in albumsGroupes) + { + // On récupère le premier titre du groupe pour afficher l'image de l'album + var premierTitre = groupe.First(); + +
+
+ Pochette de @groupe.Key +
+ +
+

@groupe.Key

+ + + + + + + + + + @foreach (var titre in groupe) + { + // Conversion des secondes en format MM:SS + var minutes = titre.Duree / 60; + var secondes = titre.Duree % 60; + var dureeFormatee = $"{minutes}:{secondes:D2}"; + + + + + + } + +
DuréeTitre
@dureeFormatee + + @titre.Libelle + +
+
+
+ } +
\ No newline at end of file diff --git a/Webzine.WebApplication/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Views/Shared/_Layout.cshtml index 2f42ca0..b807a6d 100644 --- a/Webzine.WebApplication/Views/Shared/_Layout.cshtml +++ b/Webzine.WebApplication/Views/Shared/_Layout.cshtml @@ -7,7 +7,7 @@ @* Ajout de bootstrap *@ - + @* Ajout de font-awesome *@ diff --git a/Webzine.WebApplication/Webzine.WebApplication.csproj.user b/Webzine.WebApplication/Webzine.WebApplication.csproj.user index ea9a183..2702025 100644 --- a/Webzine.WebApplication/Webzine.WebApplication.csproj.user +++ b/Webzine.WebApplication/Webzine.WebApplication.csproj.user @@ -2,9 +2,12 @@ https - MvcControllerWithActionsScaffolder + MvcControllerEmptyScaffolder root/Common/MVC/Controller RazorViewEmptyScaffolder root/Common/MVC/View + + ProjectDebugger + \ No newline at end of file From c26e48f4f22af4c71997378b2b80ddaef786460b Mon Sep 17 00:00:00 2001 From: "josephine.vetu" Date: Thu, 5 Mar 2026 14:31:04 +0100 Subject: [PATCH 2/2] =?UTF-8?q?fix/=20Nom=20de=20la=20m=C3=A9thode=20Artis?= =?UTF-8?q?teFactory=20modifi=C3=A9.=20Changement=20du=20nom=20du=20dossie?= =?UTF-8?q?r=20Controller=20en=20Controllers.=20Changement=20des=20imports?= =?UTF-8?q?=20de=20bootstrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.Entity/Fixtures/ArtisteFactory.cs | 2 +- .../{Controller => Controllers}/AccueilController.cs | 0 .../{Controller => Controllers}/ApiController.cs | 2 +- .../{Controller => Controllers}/ArtisteController.cs | 2 +- .../{Controller => Controllers}/TitreController.cs | 2 +- Webzine.WebApplication/Views/Shared/_Layout.cshtml | 3 ++- 6 files changed, 6 insertions(+), 5 deletions(-) rename Webzine.WebApplication/{Controller => Controllers}/AccueilController.cs (100%) rename Webzine.WebApplication/{Controller => Controllers}/ApiController.cs (93%) rename Webzine.WebApplication/{Controller => Controllers}/ArtisteController.cs (96%) rename Webzine.WebApplication/{Controller => Controllers}/TitreController.cs (99%) diff --git a/Webzine.Entity/Fixtures/ArtisteFactory.cs b/Webzine.Entity/Fixtures/ArtisteFactory.cs index 4161e35..e9af87b 100644 --- a/Webzine.Entity/Fixtures/ArtisteFactory.cs +++ b/Webzine.Entity/Fixtures/ArtisteFactory.cs @@ -13,7 +13,7 @@ namespace Webzine.Entity.Fixtures /// /// /// - public static Artiste FindByName(string nom) + public static Artiste SeedArtisteByName(string nom) { // On définit nos albums "bouchonnés" var albumsData = new[] diff --git a/Webzine.WebApplication/Controller/AccueilController.cs b/Webzine.WebApplication/Controllers/AccueilController.cs similarity index 100% rename from Webzine.WebApplication/Controller/AccueilController.cs rename to Webzine.WebApplication/Controllers/AccueilController.cs diff --git a/Webzine.WebApplication/Controller/ApiController.cs b/Webzine.WebApplication/Controllers/ApiController.cs similarity index 93% rename from Webzine.WebApplication/Controller/ApiController.cs rename to Webzine.WebApplication/Controllers/ApiController.cs index 70d2c51..39e8825 100644 --- a/Webzine.WebApplication/Controller/ApiController.cs +++ b/Webzine.WebApplication/Controllers/ApiController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace Webzine.WebApplication.Controller; +namespace Webzine.WebApplication.Controllers; public class ApiController : ControllerBase { diff --git a/Webzine.WebApplication/Controller/ArtisteController.cs b/Webzine.WebApplication/Controllers/ArtisteController.cs similarity index 96% rename from Webzine.WebApplication/Controller/ArtisteController.cs rename to Webzine.WebApplication/Controllers/ArtisteController.cs index 0f26971..0f5b91a 100644 --- a/Webzine.WebApplication/Controller/ArtisteController.cs +++ b/Webzine.WebApplication/Controllers/ArtisteController.cs @@ -31,7 +31,7 @@ namespace Webzine.WebApplication.Controllers .ToTitleCase(nom.Replace("-", " ")); // On appelle la factory pour obtenir l'artiste unique - var artiste = ArtisteFactory.FindByName(nomPropre); + var artiste = ArtisteFactory.SeedArtisteByName(nomPropre); if (artiste == null) { diff --git a/Webzine.WebApplication/Controller/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs similarity index 99% rename from Webzine.WebApplication/Controller/TitreController.cs rename to Webzine.WebApplication/Controllers/TitreController.cs index 42693d4..23d400f 100644 --- a/Webzine.WebApplication/Controller/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -3,7 +3,7 @@ using Webzine.Entity; using Webzine.Entity.Fixtures; using Webzine.WebApplication.ViewsModels.Titre; -namespace Webzine.WebApplication.Controller; +namespace Webzine.WebApplication.Controllers; /// /// Contrôleur responsable de la gestion des titres musicaux : diff --git a/Webzine.WebApplication/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Views/Shared/_Layout.cshtml index b807a6d..9573fa6 100644 --- a/Webzine.WebApplication/Views/Shared/_Layout.cshtml +++ b/Webzine.WebApplication/Views/Shared/_Layout.cshtml @@ -6,7 +6,8 @@ @ViewData["Title"] - Webzine @* Ajout de bootstrap *@ - + + @* Ajout de font-awesome *@