54 lines
2.2 KiB
C#
54 lines
2.2 KiB
C#
namespace Webzine.Business;
|
|
|
|
using Webzine.Business.Contracts;
|
|
using Webzine.Business.Contracts.Dto;
|
|
using Webzine.Repository.Contracts;
|
|
|
|
/// <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()
|
|
{
|
|
string artisteLePlusChronique = this.titreRepository.FindMostReviewedArtistName() ?? string.Empty;
|
|
string albumLePlusChronique = this.titreRepository.FindArtistNameWithMostReviewedAlbums() ?? string.Empty;
|
|
var musiqueLaPlusJouee = this.titreRepository.FindMostPlayedTitle();
|
|
|
|
return new DashboardDTO
|
|
{
|
|
NombreArtistes = this.artisteRepository.Count(),
|
|
ArtisteLePlusChronique = artisteLePlusChronique,
|
|
AlbumLePlusChronique = albumLePlusChronique,
|
|
NombreBiographies = this.artisteRepository.CountWithBiography(),
|
|
IdMusiqueLaPlusJouee = musiqueLaPlusJouee?.IdTitre ?? 0,
|
|
MusiqueLaPlusJouee = musiqueLaPlusJouee?.Libelle ?? string.Empty,
|
|
NombreTitres = this.titreRepository.Count(),
|
|
NombreGenres = this.styleRepository.Count(),
|
|
NombreLectures = this.titreRepository.CountLecture(),
|
|
NombreLikes = this.titreRepository.CountLike(),
|
|
};
|
|
}
|
|
} |