Merge branch 'dev' into j3/TODO_erreurs
This commit is contained in:
@@ -2,29 +2,25 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.Business.Contracts.Dto;
|
||||
|
||||
[Area("Administration")]
|
||||
public class DashboardController : Controller // TODO à refaire
|
||||
{
|
||||
private readonly ILogger<DashboardController> logger;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
private readonly IArtisteRepository artisteRepository;
|
||||
private readonly ITitreRepository titreRepository;
|
||||
private readonly IDashboardService dashboardService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DashboardController"/> class.
|
||||
/// Initialise une nouvelle instance de la classe <see cref="DashboardController"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="styleRepository">Repository des styles injecté.</param>
|
||||
public DashboardController(ILogger<DashboardController> logger, IStyleRepository styleRepository, IArtisteRepository artisteRepository, ITitreRepository titreRepository)
|
||||
/// <param name="dashboardService">Service de calcul des statistiques du tableau de bord.</param>
|
||||
public DashboardController(ILogger<DashboardController> logger, IDashboardService dashboardService)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.styleRepository = styleRepository;
|
||||
this.artisteRepository = artisteRepository;
|
||||
this.titreRepository = titreRepository;
|
||||
this.dashboardService = dashboardService;
|
||||
|
||||
this.logger.LogInformation("Initialisation du contrôleur TitreController.");
|
||||
}
|
||||
@@ -35,42 +31,8 @@ public class DashboardController : Controller // TODO à refaire
|
||||
/// <returns>La vue Index du tableau de bord.</returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
var artisteLePlusChronique = this.titreRepository.FindAll()
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.First();
|
||||
DashboardDTO data = this.dashboardService.GetDashboardData();
|
||||
|
||||
var albumLePlusChronique = this.titreRepository.FindAll()
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Select(t => t.Album).Distinct().Count())
|
||||
.First();
|
||||
|
||||
var musiqueLaPlusJouee = this.titreRepository.FindAll()
|
||||
.OrderByDescending(t => t.NbLectures)
|
||||
.First();
|
||||
|
||||
var model = new DashboardViewModel
|
||||
{
|
||||
NombreArtistes = this.artisteRepository.FindAll().Count(),
|
||||
|
||||
ArtisteLePlusChronique = artisteLePlusChronique.Key.Nom,
|
||||
|
||||
AlbumLePlusChronique = albumLePlusChronique.Key.Nom,
|
||||
|
||||
NombreBiographies = this.artisteRepository.FindAll().Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||
|
||||
IdMusiqueLaPlusJouee = musiqueLaPlusJouee.IdTitre,
|
||||
MusiqueLaPlusJouee = musiqueLaPlusJouee.Libelle,
|
||||
|
||||
NombreTitres = this.titreRepository.Count(),
|
||||
|
||||
NombreGenres = this.styleRepository.FindAll().Count(),
|
||||
|
||||
NombreLectures = this.titreRepository.FindAll().Sum(t => t.NbLectures),
|
||||
|
||||
NombreLikes = this.titreRepository.FindAll().Sum(t => t.NbLikes),
|
||||
};
|
||||
|
||||
return this.View(model);
|
||||
return this.View(data);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// ViewModel pour le tableau de bord de l'administration du webzine.
|
||||
/// </summary>
|
||||
public class DashboardViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Définit le nombre total d'artistes chroniqués dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreArtistes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nom de l'artiste le plus chroniqué dans le webzine.
|
||||
/// </summary>
|
||||
public string ArtisteLePlusChronique { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nom de l'album le plus chroniqué dans le webzine.
|
||||
/// </summary>
|
||||
public string AlbumLePlusChronique { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nombre total de biographies d'artistes dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreBiographies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit l'identifiant de la biographie d'artiste la plus lue dans le webzine.
|
||||
/// </summary>
|
||||
public int IdMusiqueLaPlusJouee { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nom de la biographie d'artiste la plus lue dans le webzine.
|
||||
/// </summary>
|
||||
public string MusiqueLaPlusJouee { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nombre total de titres chroniqués dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreTitres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nombre total de genres musicaux chroniqués dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreGenres { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nombre total de chroniques d'albums dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreLectures { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Définit le nombre total de likes sur les chroniques d'albums dans le webzine.
|
||||
/// </summary>
|
||||
public int NombreLikes { get; set; }
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
{
|
||||
<tr class="align-middle">
|
||||
<td>
|
||||
<a asp-action="Details" asp-controller="Titre" asp-route-id="@commentaire.Titre.IdTitre">
|
||||
<a asp-controller="Titre" asp-action="Index" asp-route-id="@commentaire.Titre.IdTitre">
|
||||
@commentaire.Titre.Libelle
|
||||
</a>
|
||||
</td>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.DashboardViewModel
|
||||
@using Webzine.Business.Contracts.Dto
|
||||
@model DashboardDTO
|
||||
|
||||
<h1 class="mb-4">Tableau de bord</h1>
|
||||
|
||||
@@ -94,7 +95,7 @@
|
||||
<div class="col-md-4">
|
||||
<a asp-area=""
|
||||
asp-controller="Titre"
|
||||
asp-action="Details"
|
||||
asp-action="Index"
|
||||
asp-route-id="@Model.IdMusiqueLaPlusJouee">
|
||||
<div class="ratio ratio-4x3">
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
/// </summary>
|
||||
/// <param name="nom">Le nom de l'artiste à rechercher, formaté en kebab-case (ex: "fatal-bazooka").</param>
|
||||
/// <returns>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é.</returns>
|
||||
[HttpGet("/artiste/{nom}")]
|
||||
public IActionResult Index(string nom)
|
||||
{
|
||||
this.logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom);
|
||||
|
||||
@@ -15,7 +15,6 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// affichage des details, filtrage par style,
|
||||
/// ajout de likes, commentaires et recherche.
|
||||
/// </summary>
|
||||
[Route("titre")]
|
||||
public class TitreController : Controller
|
||||
{
|
||||
private readonly ILogger<TitreController> logger;
|
||||
@@ -40,8 +39,7 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// </summary>
|
||||
/// <param name="id">Identifiant du titre.</param>
|
||||
/// <returns>Vue des details ou 404 si introuvable.</returns>
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult Details(int id)
|
||||
public IActionResult Index(int id)
|
||||
{
|
||||
this.logger.LogInformation("Demande d'affichage du detail pour le titre ID {Id}.", id);
|
||||
|
||||
@@ -82,7 +80,6 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// </summary>
|
||||
/// <param name="style">Nom du style musical.</param>
|
||||
/// <returns>Vue contenant la liste filtree.</returns>
|
||||
[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);
|
||||
@@ -103,7 +100,7 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// </summary>
|
||||
/// <param name="model">Modele contenant l'identifiant du titre.</param>
|
||||
/// <returns>Redirection vers la page detail.</returns>
|
||||
[HttpPost("like")]
|
||||
[HttpPost]
|
||||
public IActionResult Like(TitreLike model)
|
||||
{
|
||||
this.logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
|
||||
@@ -126,7 +123,7 @@ namespace Webzine.WebApplication.Controllers
|
||||
/// </summary>
|
||||
/// <param name="model">Donnees du commentaire.</param>
|
||||
/// <returns>Redirection vers la page detail.</returns>
|
||||
[HttpPost("comment")]
|
||||
[HttpPost]
|
||||
public IActionResult Comment(TitreComment model)
|
||||
{
|
||||
if (!this.ModelState.IsValid)
|
||||
|
||||
@@ -7,6 +7,37 @@ public static class RouteConfiguration
|
||||
/// </summary>
|
||||
public static void MapCustomRoutes(this IEndpointRouteBuilder endpoints)
|
||||
{
|
||||
// ----------- TITRE -----------
|
||||
endpoints.MapControllerRoute(
|
||||
name: "TitreStyle",
|
||||
pattern: "titres/style/{style}",
|
||||
defaults: new { controller = "Titre", action = "Style" });
|
||||
|
||||
endpoints.MapControllerRoute(
|
||||
name: "TitreIndex",
|
||||
pattern: "titre/{id}",
|
||||
defaults: new { controller = "Titre", action = "Index" });
|
||||
|
||||
endpoints.MapControllerRoute(
|
||||
name: "ArtisteIndex",
|
||||
pattern: "artiste/{nom}",
|
||||
defaults: new { controller = "Artiste", action = "Index" });
|
||||
|
||||
// ----------- ADMIN -----------
|
||||
var adminRoutes = new Dictionary<string, string>
|
||||
{
|
||||
{ "artistes", "Artiste" }, { "commentaires", "Commentaire" }, { "styles", "Style" }, { "titres", "Titre" },
|
||||
};
|
||||
|
||||
foreach (var route in adminRoutes)
|
||||
{
|
||||
endpoints.MapControllerRoute(
|
||||
name: $"Admin{route.Value}Index",
|
||||
pattern: $"administration/{route.Key}",
|
||||
defaults: new { area = "Administration", controller = route.Value, action = "Index" });
|
||||
}
|
||||
|
||||
// --- AUTRE PROUTES ---
|
||||
endpoints.MapControllerRoute(
|
||||
name: "areas",
|
||||
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
|
||||
|
||||
@@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore;
|
||||
using NLog;
|
||||
using NLog.Web;
|
||||
|
||||
using Webzine.Business;
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.EntitiesContext;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
@@ -67,6 +69,8 @@ try
|
||||
builder.Services.AddSingleton<InMemoryDataStore>();
|
||||
}
|
||||
|
||||
builder.Services.AddScoped<IDashboardService, DashboardService>();
|
||||
|
||||
// https://learn.microsoft.com/fr-fr/aspnet/core/performance/response-compression?view=aspnetcore-10.0#configuration
|
||||
// Ajoute le service de compression des réponses HTTP pour réduire la taille des données envoyées au client et améliorer les performances de l'application.
|
||||
builder.Services.AddResponseCompression();
|
||||
@@ -78,6 +82,8 @@ try
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||
db.Database.EnsureCreated();
|
||||
|
||||
if (shouldSeed)
|
||||
{
|
||||
db.Database.EnsureDeleted();
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
@titre.Artiste.Nom
|
||||
</a>
|
||||
-
|
||||
<a asp-action="Details"
|
||||
<a asp-action="Index"
|
||||
asp-controller="Titre"
|
||||
asp-route-id="@titre.IdTitre">
|
||||
@titre.Libelle
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="d-flex flex-wrap align-items-center gap-3">
|
||||
<a asp-action="Details"
|
||||
<a asp-action="Index"
|
||||
asp-controller="Titre"
|
||||
asp-route-id="@titre.IdTitre"
|
||||
class="btn btn-primary btn-sm">
|
||||
@@ -90,7 +90,7 @@
|
||||
<img class="card-img-top" src="@titre.UrlJaquette" alt="@titre.Album" loading="lazy" />
|
||||
|
||||
<div class="card-body">
|
||||
<a asp-controller="Titre" asp-action="Details" asp-route-id="@titre.IdTitre" class="card-link">
|
||||
<a asp-controller="Titre" asp-action="Index" asp-route-id="@titre.IdTitre" class="card-link">
|
||||
@titre.Libelle
|
||||
</a>
|
||||
<br />
|
||||
|
||||
@@ -56,7 +56,7 @@ else
|
||||
<td class="text-secondary font-monospace">@dureeFormatee</td>
|
||||
<td>
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Details"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre"
|
||||
class="text-primary">
|
||||
@titre.Libelle
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
@if (!Model.Artistes.Any())
|
||||
{
|
||||
<div class="alert alert-info">
|
||||
<p>Aucun artiste n'a été trouvé.</p>
|
||||
<p>Aucun artiste n'a été trouvé.</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
@if (!Model.Titres.Any())
|
||||
{
|
||||
<div class="alert alert-info">
|
||||
<p>Aucun titre n'a été trouvé.</p>
|
||||
<p>Aucun titre n'a été trouvé.</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
{
|
||||
<div class="d-flex align-items-start my-3">
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Details"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre"
|
||||
class="me-3 text-black">
|
||||
<img src="@titre.UrlJaquette" alt="@titre.Libelle" width="70" height="70" class="object-fit-cover" loading="lazy" />
|
||||
@@ -58,7 +58,7 @@
|
||||
</a>
|
||||
-
|
||||
<a asp-controller="Titre"
|
||||
asp-action="Details"
|
||||
asp-action="Index"
|
||||
asp-route-id="@titre.IdTitre">
|
||||
@titre.Libelle
|
||||
</a>
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Webzine.Business.Contracts\Webzine.Business.Contracts.csproj" />
|
||||
<ProjectReference Include="..\Webzine.Business\Webzine.Business.csproj" />
|
||||
<ProjectReference Include="..\Webzine.EntitiesContext\Webzine.EntitiesContext.csproj" />
|
||||
<ProjectReference Include="..\Webzine.Entity\Webzine.Entity.csproj" />
|
||||
<ProjectReference Include="..\Webzine.Repository\Webzine.Repository.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user