feat: implémenter le service de tableau de bord et DTO pour les statistiques du tableau de bord
This commit is contained in:
@@ -1,30 +1,26 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers;
|
||||
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.Business.Contracts.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
using Webzine.Repository.Contracts;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels;
|
||||
|
||||
[Area("Administration")]
|
||||
public class DashboardController : Controller
|
||||
{
|
||||
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
|
||||
/// <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 = 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; }
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user