From 645cd1990936a36f09c380be87471834a9fc41a2 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Thu, 9 Apr 2026 11:38:25 +0200 Subject: [PATCH] #216 : Ajout de la pagination sur la page style. --- .../ITitreRepository.cs | 16 +++++++++ Webzine.Repository/DbTitreRepository.cs | 14 ++++++++ Webzine.Repository/LocalTitreRepository.cs | 14 ++++++++ .../Controllers/TitreController.cs | 14 ++++++-- .../ViewModels/Titre/TitreStyle.cs | 10 ++++++ .../Views/Titre/Style.cshtml | 35 ++++++++++++++++++- 6 files changed, 99 insertions(+), 4 deletions(-) diff --git a/Webzine.Repository.Contracts/ITitreRepository.cs b/Webzine.Repository.Contracts/ITitreRepository.cs index 4f19c38..394b601 100644 --- a/Webzine.Repository.Contracts/ITitreRepository.cs +++ b/Webzine.Repository.Contracts/ITitreRepository.cs @@ -72,6 +72,22 @@ /// Une collection de titres correspondant au critère de recherche, triée par libellé. IEnumerable SearchByStyle(string libelle); + /// + /// Retourne une liste de titre filtré par nom et paginé. + /// + /// Nombre de titres a passer. + /// Nombre de titre récupéré. + /// Nom du style. + /// Une liste de titre. + IEnumerable SearchByStylePaginate(int offset, int limit, string libelle); + + /// + /// Compter le nombre de titres au sein d'un style. + /// + /// Style de la musique. + /// Un entier. + int CountByStyle(string libelle); + /// /// Met à jour un titre dans la liste des titres en fonction de son identifiant. Si aucun titre correspondant à l'identifiant du titre fourni n'est trouvé, un message d'avertissement est enregistré dans les logs et aucune mise à jour n'est effectuée. /// diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index ae14698..752e6b1 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -314,6 +314,20 @@ public class DbTitreRepository : ITitreRepository } } + /// + public IEnumerable SearchByStylePaginate(int offset, int limit, string libelle) + { + return this.SearchByStyle(libelle).Paginate(offset, limit); + } + + /// + public int CountByStyle(string libelle) + { + return this.context.Titres + .Where(t => t.Styles.Any(s => s.Libelle.ToLower() == libelle.ToLower())) + .Count(); + } + /// public int CountLike() { diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs index cb9877f..0f5257b 100644 --- a/Webzine.Repository/LocalTitreRepository.cs +++ b/Webzine.Repository/LocalTitreRepository.cs @@ -112,6 +112,20 @@ public class LocalTitreRepository : ITitreRepository .Where(t => t.Styles.Any(s => s.Libelle == libelle)); } + /// + public IEnumerable SearchByStylePaginate(int offset, int limit, string libelle) + { + return this.SearchByStyle(libelle).Paginate(offset, limit); + } + + /// + public int CountByStyle(string libelle) + { + return this.dataStore.Titres + .Where(t => t.Styles.Any(s => s.Libelle == libelle)) + .Count(); + } + /// public void Update(Titre titre) { diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index 9aefe66..27a0329 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -67,17 +67,25 @@ namespace Webzine.WebApplication.Controllers /// Affiche les titres correspondant a un style musical donne. /// /// Nom du style musical. + /// Numéro de la page. /// Vue contenant la liste filtree. - public IActionResult Style(string style) + [Route("/titres/styles/{style}", Name = "TitresParStyle")] + public IActionResult Style(string style, int page = 0) { - this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style); + var offset = page * 10; + var limit = 10; + var titresFiltres = this.titreRepository.SearchByStylePaginate(offset, limit, style).ToList(); + var totalTitres = this.titreRepository.CountByStyle(style); + var totalPages = (int)Math.Ceiling((double)totalTitres / limit); - var titresFiltres = this.titreRepository.SearchByStyle(style).ToList(); + this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style); var vm = new TitreStyle { StyleName = style, Titres = titresFiltres.Select(MapTitreItem).ToList(), + Page = page, + TotalPages = totalPages, }; return this.View(vm); diff --git a/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs b/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs index 10c8a45..319bc5b 100644 --- a/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs +++ b/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs @@ -14,4 +14,14 @@ public class TitreStyle /// Définit la liste des items de titre associés au style musical. /// public List Titres { get; set; } = new (); + + /// + /// Obtient ou définit le numéro de page pour la pagination des titres affichés sur la page d'accueil. + /// + public int Page { get; set; } + + /// + /// Nombre total de page. + /// + public int TotalPages { get; set; } } \ No newline at end of file diff --git a/Webzine.WebApplication/Views/Titre/Style.cshtml b/Webzine.WebApplication/Views/Titre/Style.cshtml index 6970347..1c308b9 100644 --- a/Webzine.WebApplication/Views/Titre/Style.cshtml +++ b/Webzine.WebApplication/Views/Titre/Style.cshtml @@ -29,7 +29,7 @@ - @titre.Libelle + @titre.Libelle @@ -55,6 +55,39 @@ } } +
+ @if (Model.Page > 0) + { + + << Titre plus récent + + } + else + { +
+ } + +

+ Page : @(Model.Page + 1) sur @Model.TotalPages +

+ + @if (Model.Page < Model.TotalPages - 1) + { + + Titre plus anciens >> + + } + else + { +
+ } +
\ No newline at end of file