#202 : Optimisation du Dashboard.
This commit is contained in:
@@ -325,4 +325,100 @@ public class DbTitreRepository : ITitreRepository
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int CountLike()
|
||||
{
|
||||
try
|
||||
{
|
||||
var likes = this.context.Titres.Sum(t => t.NbLikes);
|
||||
return likes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogError(ex, "Erreur lors de la récupération des likes.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int CountLecture()
|
||||
{
|
||||
try
|
||||
{
|
||||
var lectures = this.context.Titres.Sum(t => t.NbLectures);
|
||||
return lectures;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogError(ex, "Erreur lors de la récupération des lectures.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string? FindMostReviewedArtistName()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.context.Titres
|
||||
.AsNoTracking()
|
||||
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
|
||||
.OrderByDescending(g => g.Count())
|
||||
.ThenBy(g => g.Key.Nom)
|
||||
.Select(g => g.Key.Nom)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste le plus chroniqué.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string? FindArtistNameWithMostReviewedAlbums()
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.context.Titres
|
||||
.AsNoTracking()
|
||||
.GroupBy(t => new { t.IdArtiste, t.Artiste.Nom })
|
||||
.Select(g => new
|
||||
{
|
||||
g.Key.Nom,
|
||||
AlbumCount = g.Select(t => t.Album).Distinct().Count(),
|
||||
})
|
||||
.OrderByDescending(x => x.AlbumCount)
|
||||
.ThenBy(x => x.Nom)
|
||||
.Select(x => x.Nom)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le plus d'albums chroniqués.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public (int IdTitre, string Libelle)? FindMostPlayedTitle()
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = this.context.Titres
|
||||
.AsNoTracking()
|
||||
.OrderByDescending(t => t.NbLectures)
|
||||
.ThenBy(t => t.Libelle)
|
||||
.Select(t => new { t.IdTitre, t.Libelle })
|
||||
.FirstOrDefault();
|
||||
|
||||
return result == null ? null : (result.IdTitre, result.Libelle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger.LogError(ex, "Erreur lors de la recherche du titre le plus joué.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user