#202 : Optimisation du Dashboard.
This commit is contained in:
@@ -2,7 +2,6 @@ namespace Webzine.Business;
|
||||
|
||||
using Webzine.Business.Contracts;
|
||||
using Webzine.Business.Contracts.Dto;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Repository.Contracts;
|
||||
|
||||
/// <summary>
|
||||
@@ -34,37 +33,22 @@ public class DashboardService : IDashboardService
|
||||
/// <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();
|
||||
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.Nom,
|
||||
AlbumLePlusChronique = albumLePlusChronique.Nom,
|
||||
NombreBiographies = this.artisteRepository.Count(a => !string.IsNullOrEmpty(a.Biographie)),
|
||||
IdMusiqueLaPlusJouee = musiqueLaPlusJouee.IdTitre,
|
||||
MusiqueLaPlusJouee = musiqueLaPlusJouee.Libelle,
|
||||
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 = titres.Sum(t => t.NbLectures),
|
||||
NombreLikes = titres.Sum(t => t.NbLikes),
|
||||
NombreLectures = this.titreRepository.CountLecture(),
|
||||
NombreLikes = this.titreRepository.CountLike(),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user