Merge branch 'dev' into j3/feat/business-logic/titre-admin
# Conflicts: # Webzine.Business/Webzine.Business.csproj # Webzine.WebApplication/Program.cs
This commit is contained in:
71
Webzine.Business/DashboardService.cs
Normal file
71
Webzine.Business/DashboardService.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
namespace Webzine.Business;
|
||||
|
||||
using Contracts.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// Implémentation de <see cref="IDashboardService"/>.
|
||||
/// Orchestre plusieurs appels aux repositories pour produire les statistiques du tableau de bord.
|
||||
/// </summary>
|
||||
public class DashboardService : IDashboardService
|
||||
{
|
||||
private readonly IArtisteRepository artisteRepository;
|
||||
private readonly ITitreRepository titreRepository;
|
||||
private readonly IStyleRepository styleRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DashboardService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="artisteRepository">Repository des artistes.</param>
|
||||
/// <param name="titreRepository">Repository des titres.</param>
|
||||
/// <param name="styleRepository">Repository des styles.</param>
|
||||
public DashboardService(
|
||||
IArtisteRepository artisteRepository,
|
||||
ITitreRepository titreRepository,
|
||||
IStyleRepository styleRepository)
|
||||
{
|
||||
this.artisteRepository = artisteRepository;
|
||||
this.titreRepository = titreRepository;
|
||||
this.styleRepository = styleRepository;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DashboardDTO GetDashboardData()
|
||||
{
|
||||
IEnumerable<Titre> titres = this.titreRepository.FindAll();
|
||||
|
||||
Artiste? artisteLePlusChronique = titres
|
||||
.GroupBy(t => t.Artiste)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.FirstOrDefault()
|
||||
?.Key;
|
||||
|
||||
Artiste? albumLePlusChronique = titres
|
||||
.GroupBy(t => (t.Artiste, t.Album))
|
||||
.GroupBy(g => g.Key.Artiste)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.FirstOrDefault()
|
||||
?.Key;
|
||||
|
||||
Titre? musiqueLaPlusJouee = titres
|
||||
.OrderByDescending(t => t.NbLectures)
|
||||
.FirstOrDefault();
|
||||
|
||||
return new DashboardDTO
|
||||
{
|
||||
NombreArtistes = this.artisteRepository.Count(),
|
||||
ArtisteLePlusChronique = artisteLePlusChronique.Nom,
|
||||
AlbumLePlusChronique = albumLePlusChronique.Nom,
|
||||
NombreBiographies = this.artisteRepository.Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||
IdMusiqueLaPlusJouee = musiqueLaPlusJouee.IdTitre,
|
||||
MusiqueLaPlusJouee = musiqueLaPlusJouee.Libelle,
|
||||
NombreTitres = this.titreRepository.Count(),
|
||||
NombreGenres = this.styleRepository.Count(),
|
||||
NombreLectures = titres.Sum(t => t.NbLectures),
|
||||
NombreLikes = titres.Sum(t => t.NbLikes),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user