From 94b84bdfb1a043eb573f56bae03d911d3ee13b79 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Thu, 5 Mar 2026 13:54:09 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20de=20la=20page=20d'accueil.=20Aj?= =?UTF-8?q?out=20des=20param=C3=A8tres=20dans=20le=20fichier=20appsettings?= =?UTF-8?q?=20pour=20choisir=20le=20nombre=20de=20chronique=20ou=20de=20ti?= =?UTF-8?q?tres=20les=20plus=20likes=20=C3=A0=20afficher.=20Ajout=20des=20?= =?UTF-8?q?relations=20qui=20permettent=20de=20fakes=20les=20donn=C3=A9es?= =?UTF-8?q?=20affich=C3=A9s=20sur=20la=20page=20d'accueil.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.Entity/Titre.cs | 2 +- Webzine.Repository/Fake/TitreFactory.cs | 63 ++++++ Webzine.Repository/Webzine.Repository.csproj | 4 + .../Controllers/AccueilController.cs | 89 +++------ .../Accueil/AccueilIndexViewModel.cs | 10 + .../Views/Accueil/Index.cshtml | 185 ++++++------------ .../Webzine.WebApplication.csproj | 14 +- Webzine.WebApplication/appsettings.json | 4 + 8 files changed, 170 insertions(+), 201 deletions(-) create mode 100644 Webzine.Repository/Fake/TitreFactory.cs create mode 100644 Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs diff --git a/Webzine.Entity/Titre.cs b/Webzine.Entity/Titre.cs index 2fd9671..f8d299c 100644 --- a/Webzine.Entity/Titre.cs +++ b/Webzine.Entity/Titre.cs @@ -64,4 +64,4 @@ namespace Webzine.Entity public List Commentaires { get; set; } } - } +} diff --git a/Webzine.Repository/Fake/TitreFactory.cs b/Webzine.Repository/Fake/TitreFactory.cs new file mode 100644 index 0000000..f92bf9d --- /dev/null +++ b/Webzine.Repository/Fake/TitreFactory.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using Faker; +using Webzine.Entity; + +namespace Webzine.Repository.Fake +{ + public static class FakeDataFactory + { + //https://cdn-images.dzcdn.net/images/cover/311bba0fc112d15f72c8b5a65f0456c1/1900x1900-000000-80-0-0.jpg", + public static List GetArtistes(int count = 10) + { + var artistes = new List(); + + for (int i = 1; i <= count; i++) + { + artistes.Add(new Artiste + { + IdArtiste = i, + Nom = Name.FullName(), + Biographie = Lorem.Paragraph(), + Titres = new List() + }); + } + + return artistes; + } + + public static List GetTitres(int count = 40) + { + var artistes = GetArtistes(); + var titres = new List(); + + for (int i = 1; i <= count; i++) + { + var artiste = artistes[RandomNumber.Next(0, artistes.Count - 1)]; + + var titre = new Titre + { + IdTitre = i, + IdArtiste = artiste.IdArtiste, + Artiste = artiste, + Libelle = Lorem.Sentence(3), + Chronique = Lorem.Paragraph(), + DateCreation = DateTime.Now.AddDays(-RandomNumber.Next(1, 100)), + DateSortie = DateTime.Now.AddYears(-RandomNumber.Next(1, 20)), + Duree = RandomNumber.Next(120, 420), + UrlJaquette = "https://picsum.photos/300", + UrlEcoute = Internet.Url(), + NbLectures = RandomNumber.Next(0, 500), + NbLikes = RandomNumber.Next(0, 200), + Album = Lorem.Sentence(2), + Commentaires = new List() + }; + + titres.Add(titre); + artiste.Titres.Add(titre); + } + + return titres; + } + } +} diff --git a/Webzine.Repository/Webzine.Repository.csproj b/Webzine.Repository/Webzine.Repository.csproj index 33c0658..00cfc3d 100644 --- a/Webzine.Repository/Webzine.Repository.csproj +++ b/Webzine.Repository/Webzine.Repository.csproj @@ -21,4 +21,8 @@ + + + + diff --git a/Webzine.WebApplication/Controllers/AccueilController.cs b/Webzine.WebApplication/Controllers/AccueilController.cs index 32e2e49..5be79f9 100644 --- a/Webzine.WebApplication/Controllers/AccueilController.cs +++ b/Webzine.WebApplication/Controllers/AccueilController.cs @@ -1,83 +1,40 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Webzine.Repository.Fake; +using Webzine.WebApplication.ViewModels.Accueil; namespace Webzine.WebApplication.Controllers { public class AccueilController : Controller { + private readonly IConfiguration _configuration; + + public AccueilController(IConfiguration configuration) + { + _configuration = configuration; + } + // GET: AccueilController public ActionResult Index() { - return View(); - } + var derniereChronique = _configuration.GetValue("Webzine:NombreDerniereChronique"); + var topTitres = _configuration.GetValue("Webzine:NombreDeTopTitres"); + var titres = FakeDataFactory.GetTitres(); - // GET: AccueilController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: AccueilController/Create - public ActionResult Create() - { - return View(); - } - - // POST: AccueilController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) - { - try + var vm = new AccueilIndexViewModel { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } + DerniersTitres = titres + .OrderByDescending(t => t.DateCreation) + .Take(derniereChronique) + .ToList(), - // GET: AccueilController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } + TopTitres = titres + .OrderByDescending(t => t.NbLikes) + .Take(topTitres) + .ToList() + }; - // POST: AccueilController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: AccueilController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: AccueilController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } + return View(vm); } } } diff --git a/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs b/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs new file mode 100644 index 0000000..bd57abf --- /dev/null +++ b/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs @@ -0,0 +1,10 @@ +using Webzine.Entity; + +namespace Webzine.WebApplication.ViewModels.Accueil +{ + public class AccueilIndexViewModel + { + public IEnumerable DerniersTitres { get; set; } = []; + public IEnumerable TopTitres { get; set; } = []; + } +} diff --git a/Webzine.WebApplication/Views/Accueil/Index.cshtml b/Webzine.WebApplication/Views/Accueil/Index.cshtml index ca80480..0312cde 100644 --- a/Webzine.WebApplication/Views/Accueil/Index.cshtml +++ b/Webzine.WebApplication/Views/Accueil/Index.cshtml @@ -1,118 +1,75 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ +@model Webzine.WebApplication.ViewModels.Accueil.AccueilIndexViewModel @{ ViewData["Title"] = "Accueil"; }

Derniers titres chroniqués

-
+@* TEMPLATE *@ +@*
Alternate Text + src="" />
Justice - D.A.N.C.E

- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum - dolore eu fugiat nulla pariatur, Ut enim ad minim veniam quis nostrud - exercitation ullamco laboris nisi ut aliquip ex ea commodo ... + Insérer texte

Lire la suite
+ Date : 17/12/2022 11:08:08
-
-
- Alternate Text -
-
- Justice - D.A.N.C.E -

- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum - dolore eu fugiat nulla pariatur, Ut enim ad minim veniam quis nostrud - exercitation ullamco laboris nisi ut aliquip ex ea commodo ... -

- *@ -
- - 17/12/2022 11:08:08 -
+
+ @foreach (var titre in Model.DerniersTitres) + { +
+
+ +
+
+ @* Artiste - Titre @titre.Artiste - @titre.Libelle*@ + @titre.Artiste.Nom - @titre.Libelle + @* Chronique *@ +

+ @titre.Chronique +

+
+ Lire la suite -
- - Electro disco +
+ + @* Date de création *@ + @titre.DateCreation +
+ +
+ + @* Style *@ + STYLE +
-
-
-
- Alternate Text -
-
- Justice - D.A.N.C.E -

- Duis aute irure dolor in reprehenderit in voluptate velit esse cillum - dolore eu fugiat nulla pariatur, Ut enim ad minim veniam quis nostrud - exercitation ullamco laboris nisi ut aliquip ex ea commodo ... -

-
- Lire la suite - -
- - 17/12/2022 11:08:08 -
- - -
-
-
+ }
@@ -121,53 +78,12 @@

Titres les plus populaires

-
+@* TEMPLATE *@ +@*
Alternate Text - -
- Album
- par Artiste -
-
-
- Alternate Text - -
- Album
- par Artiste -
-
-
- Alternate Text + src="" alt="Alternate Text" />
Album
@@ -175,4 +91,21 @@
+
*@ +
+
+ @foreach (var titre in Model.TopTitres) + { +
+ + + +
+ } +
+
\ No newline at end of file diff --git a/Webzine.WebApplication/Webzine.WebApplication.csproj b/Webzine.WebApplication/Webzine.WebApplication.csproj index 7a445ec..cce23e9 100644 --- a/Webzine.WebApplication/Webzine.WebApplication.csproj +++ b/Webzine.WebApplication/Webzine.WebApplication.csproj @@ -7,13 +7,6 @@ Linux - - - - - - - .dockerignore @@ -32,11 +25,16 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/Webzine.WebApplication/appsettings.json b/Webzine.WebApplication/appsettings.json index 10f68b8..24a6a17 100644 --- a/Webzine.WebApplication/appsettings.json +++ b/Webzine.WebApplication/appsettings.json @@ -5,5 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, + "Webzine": { + "NombreDerniereChronique": 3, + "NombreDeTopTitres" : 5 + }, "AllowedHosts": "*" }