From 943fc00f3c00e5998eb69a460ea44362b7847624 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Thu, 2 Apr 2026 17:59:36 +0200 Subject: [PATCH 01/11] #145 : Ajout du seeder Spotify. --- .../DTOs/Spotify/SpotifyAlbumDto.cs | 34 ++ .../DTOs/Spotify/SpotifyAlbumsResponseDto.cs | 16 + .../DTOs/Spotify/SpotifyArtistDto.cs | 28 ++ .../Spotify/SpotifyArtistsContainerDto.cs | 16 + .../DTOs/Spotify/SpotifyExternalUrlsDto.cs | 9 + .../DTOs/Spotify/SpotifyImageDto.cs | 9 + .../SpotifySearchArtistsResponseDto.cs | 16 + .../DTOs/Spotify/SpotifyTokenResponseDto.cs | 16 + .../DTOs/Spotify/SpotifyTrackDto.cs | 34 ++ .../DTOs/Spotify/SpotifyTracksResponseDto.cs | 16 + .../Mappers/Spotify/SpotifyMapper.cs | 128 +++++++ Webzine.Business/Seeders/SeedDataSpotify.cs | 156 ++++++++ .../Seeders/SpotifySeederOptions.cs | 28 ++ Webzine.Business/Webzine.Business.csproj | 5 + Webzine.Documentation/SpotifySeederRecap.md | 172 +++++++++ Webzine.Entity/Fixtures/SeedDataSet.cs | 27 ++ Webzine.Entity/Fixtures/SeedDataSpotify.cs | 337 ------------------ Webzine.Entity/Webzine.Entity.csproj | 1 - Webzine.WebApplication/Program.cs | 22 +- .../Webzine.WebApplication.csproj | 1 + Webzine.WebApplication/appsettings.json | 8 +- 21 files changed, 728 insertions(+), 351 deletions(-) create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyAlbumDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyAlbumsResponseDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyArtistDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyArtistsContainerDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyExternalUrlsDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyImageDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifySearchArtistsResponseDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyTokenResponseDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyTrackDto.cs create mode 100644 Webzine.Business/DTOs/Spotify/SpotifyTracksResponseDto.cs create mode 100644 Webzine.Business/Mappers/Spotify/SpotifyMapper.cs create mode 100644 Webzine.Business/Seeders/SeedDataSpotify.cs create mode 100644 Webzine.Business/Seeders/SpotifySeederOptions.cs create mode 100644 Webzine.Documentation/SpotifySeederRecap.md create mode 100644 Webzine.Entity/Fixtures/SeedDataSet.cs delete mode 100644 Webzine.Entity/Fixtures/SeedDataSpotify.cs 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/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