diff --git a/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs
new file mode 100644
index 0000000..6a0ca27
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs
@@ -0,0 +1,34 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Objet album de spotify.
+ ///
+ public class SpotifyAlbumDto
+ {
+ ///
+ /// Id de l'album.
+ ///
+ [JsonPropertyName("id")]
+ public string Id { get; set; } = string.Empty;
+
+ ///
+ /// Nom de l'album.
+ ///
+ [JsonPropertyName("name")]
+ public string Name { get; set; } = string.Empty;
+
+ ///
+ /// Date de sortie.
+ ///
+ [JsonPropertyName("release_date")]
+ public string? ReleaseDate { get; set; }
+
+ ///
+ /// Urls de la jaquette.
+ ///
+ [JsonPropertyName("images")]
+ public List Images { get; set; } = new ();
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs
new file mode 100644
index 0000000..75e1f61
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs
@@ -0,0 +1,16 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Objet Spotify qui contient une liste d'album.
+ ///
+ public class SpotifyAlbumsResponseDto
+ {
+ ///
+ /// Container de plusieurs albums spotify.
+ ///
+ [JsonPropertyName("items")]
+ public List Items { get; set; } = new ();
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs
new file mode 100644
index 0000000..68be855
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs
@@ -0,0 +1,28 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Objet artiste retourne depuis spotify.
+ ///
+ public class SpotifyArtistDto
+ {
+ ///
+ /// Id de l'artiste.
+ ///
+ [JsonPropertyName("id")]
+ public string Id { get; set; } = string.Empty;
+
+ ///
+ /// Nom de l'artiste.
+ ///
+ [JsonPropertyName("name")]
+ public string Name { get; set; } = string.Empty;
+
+ ///
+ /// Genre musical de l'artiste.
+ ///
+ [JsonPropertyName("genres")]
+ public List Genres { get; set; } = new ();
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs
new file mode 100644
index 0000000..a737493
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs
@@ -0,0 +1,16 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Container d'artistes spotify.
+ ///
+ public class SpotifyArtistsContainerDto
+ {
+ ///
+ /// Liste d'artiste spotify.
+ ///
+ [JsonPropertyName("items")]
+ public List Items { get; set; } = new ();
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs
new file mode 100644
index 0000000..436dda8
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs
@@ -0,0 +1,9 @@
+namespace Webzine.Business.DTOs.Spotify;
+
+using System.Text.Json.Serialization;
+
+public class SpotifyExternalUrlsDto
+{
+ [JsonPropertyName("spotify")]
+ public string? Spotify { get; set; }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs
new file mode 100644
index 0000000..1e73ba1
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs
@@ -0,0 +1,9 @@
+namespace Webzine.Business.DTOs.Spotify;
+
+using System.Text.Json.Serialization;
+
+public class SpotifyImageDto
+{
+ [JsonPropertyName("url")]
+ public string? Url { get; set; }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs
new file mode 100644
index 0000000..3e89fc5
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs
@@ -0,0 +1,16 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Resultat d'une recherche spotify avec un objet artist.
+ ///
+ public class SpotifySearchArtistsResponseDto
+ {
+ ///
+ /// Liste d'artistes.
+ ///
+ [JsonPropertyName("artists")]
+ public SpotifyArtistsContainerDto? Artists { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs
new file mode 100644
index 0000000..238b693
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs
@@ -0,0 +1,16 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Recuperation Token Bearer de spotify.
+ ///
+ public class SpotifyTokenResponseDto
+ {
+ ///
+ /// Jeton d'acces.
+ ///
+ [JsonPropertyName("access_token")]
+ public string? AccessToken { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs
new file mode 100644
index 0000000..5f11220
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs
@@ -0,0 +1,34 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Objet track de spotify.
+ ///
+ public class SpotifyTrackDto
+ {
+ ///
+ /// Id de la track.
+ ///
+ [JsonPropertyName("id")]
+ public string Id { get; set; } = string.Empty;
+
+ ///
+ /// Nom de la musique.
+ ///
+ [JsonPropertyName("name")]
+ public string Name { get; set; } = string.Empty;
+
+ ///
+ /// Duree de la musique en millieseconde.
+ ///
+ [JsonPropertyName("duration_ms")]
+ public int DurationMs { get; set; }
+
+ ///
+ /// urls spotify.
+ ///
+ [JsonPropertyName("external_urls")]
+ public SpotifyExternalUrlsDto? ExternalUrls { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs b/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs
new file mode 100644
index 0000000..2de1d7a
--- /dev/null
+++ b/Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs
@@ -0,0 +1,16 @@
+namespace Webzine.Business.DTOs.Spotify
+{
+ using System.Text.Json.Serialization;
+
+ ///
+ /// Reponse spotify qui contient une liste de tracks.
+ ///
+ public class SpotifyTracksResponseDto
+ {
+ ///
+ /// Container qui contient plusieurs tracks.
+ ///
+ [JsonPropertyName("items")]
+ public List Items { get; set; } = new ();
+ }
+}
\ No newline at end of file
diff --git a/Webzine.Business/DashboardService.cs b/Webzine.Business/DashboardService.cs
index f1b566d..f68d1d5 100644
--- a/Webzine.Business/DashboardService.cs
+++ b/Webzine.Business/DashboardService.cs
@@ -2,7 +2,6 @@ namespace Webzine.Business;
using Webzine.Business.Contracts;
using Webzine.Business.Contracts.Dto;
-using Webzine.Entity;
using Webzine.Repository.Contracts;
///
@@ -34,37 +33,22 @@ public class DashboardService : IDashboardService
///
public DashboardDTO GetDashboardData()
{
- IEnumerable 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(),
};
}
}
\ No newline at end of file
diff --git a/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs b/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs
new file mode 100644
index 0000000..55aca46
--- /dev/null
+++ b/Webzine.Business/Mappers/Spotify/SpotifyMapper.cs
@@ -0,0 +1,128 @@
+namespace Webzine.Business.Mappers.Spotify
+{
+ using System.Globalization;
+
+ using Webzine.Business.DTOs.Spotify;
+ using Webzine.Entity;
+
+ ///
+ /// Mapper pour transformer les objets de Spotify (DTOs) en Entity.
+ ///
+ public static class SpotifyMapper
+ {
+ ///
+ /// Permet d'ajouter ou de creer un style.
+ ///
+ /// Dictionnaire string, Style.
+ /// Genre.
+ /// Id du style.
+ /// Le style.
+ public static Style GetOrCreateStyle(Dictionary styles, string genre, ref int nextStyleId)
+ {
+ // On verifie si le genre est présent dans la liste de styles.
+ if (!styles.TryGetValue(genre, out var style))
+ {
+ // Creation d'un nouveau style.
+ style = new Style
+ {
+ IdStyle = nextStyleId++,
+ Libelle = genre,
+ Titres = new List(),
+ };
+
+ // Ajout dans la liste.
+ styles.Add(style.Libelle, style);
+ }
+
+ return style;
+ }
+
+ ///
+ /// Creation d'un nouvel artiste a l'aide des infos Spotify.
+ ///
+ /// Artiste spotify.
+ /// Style spotify.
+ /// Id de l'artiste.
+ /// Artiste.
+ public static Artiste ToArtiste(SpotifyArtistDto artisteSpotify, List