#163 : merge de dev pour mis a jour de la branche.

This commit is contained in:
Loic Masi
2026-04-01 13:24:15 +02:00
21 changed files with 739 additions and 118 deletions

View File

@@ -1,5 +1,337 @@
namespace Webzine.Entity.Fixtures;
using System.Globalization;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Options;
public class SpotifySeederOptions
{
public string ClientId { get; set; } = string.Empty;
public string ClientSecret { get; set; } = string.Empty;
public string Market { get; set; } = "FR";
public List<string> Genres { get; set; } =
[
"rock",
"pop",
"jazz",
"hip hop",
"electronic",
"metal",
];
public int ArtistsPerGenre { get; set; } = 4;
public int AlbumsPerArtist { get; set; } = 2;
public int TracksPerAlbum { get; set; } = 4;
public int MaxCommentsPerTrack { get; set; } = 3;
}
public class SeedDataSpotify
{
private readonly HttpClient httpClient;
private readonly SpotifySeederOptions options;
public SeedDataSpotify(HttpClient httpClient, IOptions<SpotifySeederOptions> optionsAccessor)
{
this.httpClient = httpClient;
this.options = optionsAccessor.Value;
}
/// <summary>
///
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
/// <exception cref="InvalidOperationException"></exception>
public async Task<SeedDataSet> GenererJeuDeDonneesAsync(CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(this.options.ClientId) || string.IsNullOrWhiteSpace(this.options.ClientSecret))
{
throw new InvalidOperationException("Renseignez SpotifySeeder:ClientId et SpotifySeeder:ClientSecret.");
}
var token = await this.GetTokenAsync(cancellationToken);
var styles = new Dictionary<string, Style>(StringComparer.OrdinalIgnoreCase);
var artistes = new List<Artiste>();
var titres = new List<Titre>();
var commentaires = new List<Commentaire>();
var artistIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
int nextArtistId = 1;
int nextStyleId = 1;
int nextTitreId = 1;
int nextCommentaireId = 1;
foreach (var genre in this.options.Genres.Where(g => !string.IsNullOrWhiteSpace(g)))
{
var artistesSpotify = await this.GetAsync<SpotifySearchArtistsResponse>(
$"https://api.spotify.com/v1/search?q={Uri.EscapeDataString($"genre:\"{genre}\"")}&type=artist&market={this.options.Market}&limit={Math.Clamp(this.options.ArtistsPerGenre, 1, 10)}",
token,
cancellationToken);
foreach (var artisteSpotify in artistesSpotify?.Artists?.Items ??[])
{
if (string.IsNullOrWhiteSpace(artisteSpotify.Id) || !artistIds.Add(artisteSpotify.Id))
{
continue;
}
var stylesTitre = (artisteSpotify.Genres.Count > 0 ? artisteSpotify.Genres :[genre])
.Select(g => this.GetOrCreateStyle(styles, NormalizeGenre(g), ref nextStyleId))
.DistinctBy(s => s.IdStyle)
.ToList();
var artiste = new Artiste
{
IdArtiste = nextArtistId++,
Nom = Trim(artisteSpotify.Name, 50, "Artiste Spotify"),
Biographie = Trim(
$"{artisteSpotify.Name} est un artiste present sur Spotify, associe aux styles {string.Join(", ", stylesTitre.Select(s => s.Libelle))}.",
4000,
"Artiste issu du catalogue Spotify."),
Titres = new List<Titre>(),
};
artistes.Add(artiste);
var albums = await this.GetAsync<SpotifyAlbumsResponse>(
$"https://api.spotify.com/v1/artists/{artisteSpotify.Id}/albums?include_groups=album,single&market={this.options.Market}",
token,
cancellationToken);
foreach (var album in albums?.Items?.GroupBy(a => a.Name, StringComparer.OrdinalIgnoreCase).Select(g => g.First()) ??[])
{
var tracks = await this.GetAsync<SpotifyTracksResponse>(
$"https://api.spotify.com/v1/albums/{album.Id}/tracks?market={this.options.Market}&limit={Math.Clamp(this.options.TracksPerAlbum, 1, 10)}",
token,
cancellationToken);
foreach (var track in tracks?.Items ??[])
{
var titre = new Titre
{
IdTitre = nextTitreId++,
IdArtiste = artiste.IdArtiste,
Artiste = artiste,
Libelle = Trim(track.Name, 200, "Titre Spotify"),
Chronique = Trim(
$"{track.Name} est un titre de {artiste.Nom}, issu de l'album {album.Name}. Cette fiche a ete generee depuis Spotify.",
4000,
"Titre importe depuis Spotify."),
DateCreation = DateTime.UtcNow,
DateSortie = ParseDate(album.ReleaseDate),
Duree = Math.Max(1, track.DurationMs / 1000),
UrlJaquette = Trim(album.Images.FirstOrDefault()?.Url, 250, "https://placehold.co/640x640"),
UrlEcoute = Trim(track.ExternalUrls?.Spotify ?? $"https://open.spotify.com/track/{track.Id}", 250, string.Empty),
NbLectures = Random.Shared.Next(500, 50000),
NbLikes = Random.Shared.Next(50, 5000),
Album = Trim(album.Name, 200, "Album Spotify"),
Commentaires = new List<Commentaire>(),
Styles = new List<Style>(stylesTitre),
};
var commentairesTitre = SeedDataLocal.GenererListeCommentaire(
titre,
0,
Math.Clamp(this.options.MaxCommentsPerTrack, 0, 10),
nextCommentaireId);
nextCommentaireId += commentairesTitre.Count;
titre.Commentaires.AddRange(commentairesTitre);
commentaires.AddRange(commentairesTitre);
titres.Add(titre);
artiste.Titres.Add(titre);
foreach (var style in titre.Styles)
{
style.Titres.Add(titre);
}
}
}
}
}
return new SeedDataSet
{
Artistes = artistes,
Styles = styles.Values.OrderBy(s => s.IdStyle).ToList(),
Titres = titres,
Commentaires = commentaires,
};
}
private static string NormalizeGenre(string genre)
{
var value = string.IsNullOrWhiteSpace(genre) ? "Musique" : genre.Trim().Replace('-', ' ');
return CultureInfo.InvariantCulture.TextInfo.ToTitleCase(value);
}
private static string Trim(string? value, int maxLength, string fallback)
{
var result = string.IsNullOrWhiteSpace(value) ? fallback : value.Trim();
return result.Length > maxLength ? result[..maxLength] : result;
}
private static DateTime ParseDate(string? value)
{
if (string.IsNullOrWhiteSpace(value))
{
return DateTime.UtcNow;
}
if (DateTime.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var date))
{
return DateTime.SpecifyKind(date, DateTimeKind.Utc);
}
if (DateTime.TryParseExact(value, "yyyy-MM", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
return DateTime.SpecifyKind(date, DateTimeKind.Utc);
}
if (DateTime.TryParseExact(value, "yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
{
return DateTime.SpecifyKind(date, DateTimeKind.Utc);
}
return DateTime.UtcNow;
}
private Style GetOrCreateStyle(Dictionary<string, Style> styles, string libelle, ref int nextStyleId)
{
if (!styles.TryGetValue(libelle, out var style))
{
style = new Style
{
IdStyle = nextStyleId++,
Libelle = Trim(libelle, 50, "Musique"),
Titres = new List<Titre>(),
};
styles.Add(style.Libelle, style);
}
return style;
}
private async Task<string> GetTokenAsync(CancellationToken cancellationToken)
{
using var request = new HttpRequestMessage(HttpMethod.Post, "https://accounts.spotify.com/api/token");
request.Content = new FormUrlEncodedContent(
[
new KeyValuePair<string, string>("grant_type", "client_credentials"),
]);
var basic = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{this.options.ClientId}:{this.options.ClientSecret}"));
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", basic);
using var response = await this.httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
var payload = await response.Content.ReadFromJsonAsync<SpotifyTokenResponse>(cancellationToken: cancellationToken);
return payload?.AccessToken ?? throw new InvalidOperationException("Token Spotify introuvable.");
}
private async Task<T?> GetAsync<T>(string url, string token, CancellationToken cancellationToken)
{
using var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
using var response = await this.httpClient.SendAsync(request, cancellationToken);
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<T>(cancellationToken: cancellationToken);
}
private sealed class SpotifyTokenResponse
{
[JsonPropertyName("access_token")]
public string? AccessToken { get; set; }
}
private sealed class SpotifySearchArtistsResponse
{
[JsonPropertyName("artists")]
public SpotifyArtistsContainer? Artists { get; set; }
}
private sealed class SpotifyArtistsContainer
{
[JsonPropertyName("items")]
public List<SpotifyArtist> Items { get; set; } = new ();
}
private sealed class SpotifyArtist
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("genres")]
public List<string> Genres { get; set; } = new ();
}
private sealed class SpotifyAlbumsResponse
{
[JsonPropertyName("items")]
public List<SpotifyAlbum> Items { get; set; } = new ();
}
private sealed class SpotifyAlbum
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("release_date")]
public string? ReleaseDate { get; set; }
[JsonPropertyName("images")]
public List<SpotifyImage> Images { get; set; } = new ();
}
private sealed class SpotifyTracksResponse
{
[JsonPropertyName("items")]
public List<SpotifyTrack> Items { get; set; } = new ();
}
private sealed class SpotifyTrack
{
[JsonPropertyName("id")]
public string Id { get; set; } = string.Empty;
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("duration_ms")]
public int DurationMs { get; set; }
[JsonPropertyName("external_urls")]
public SpotifyExternalUrls? ExternalUrls { get; set; }
}
private sealed class SpotifyImage
{
[JsonPropertyName("url")]
public string? Url { get; set; }
}
private sealed class SpotifyExternalUrls
{
[JsonPropertyName("spotify")]
public string? Spotify { get; set; }
}
}

View File

@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.5" />
<PackageReference Include="Faker.Net" Version="2.0.163" />
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.0" />
<PackageReference Include="NLog" Version="6.1.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>

View File

@@ -25,6 +25,7 @@ namespace Webzine.Repository
/// <param name="minStyles">Nombre min de style.</param>
/// <param name="maxStyles">Nombre mac de style.</param>
public void SeedBaseDeDonnees(
SeedDataSet? jeuDeDonnees = null,
int nbArtistes = 100,
int nbTitres = 500,
int minStyles = 15,
@@ -38,6 +39,16 @@ namespace Webzine.Repository
return;
}
if (jeuDeDonnees is not null)
{
this.context.Artistes.AddRange(jeuDeDonnees.Artistes);
this.context.Styles.AddRange(jeuDeDonnees.Styles);
this.context.Titres.AddRange(jeuDeDonnees.Titres);
this.context.Commentaires.AddRange(jeuDeDonnees.Commentaires);
this.context.SaveChanges();
return;
}
List<Artiste> artistes = SeedDataLocal.GenererListeArtiste(nbArtistes);
List<Style> styles = SeedDataLocal.GenererListeStyle(minStyles, maxStyles);

View File

@@ -50,14 +50,37 @@ public class ArtisteController : Controller
/// <returns>Redirection.</returns>
public IActionResult Create()
{
var model = new AdminArtisteForm
return this.View();
}
/// <summary>
/// Formulaire de création d'un artiste.
/// </summary>
/// <param name="model">Paramètre nécessaire pour la création d'un artiste.</param>
/// <returns>Redirection sur la page Index.</returns>
[HttpPost]
public IActionResult Create(ArtisteCreateViewModel model)
{
Id = 0,
Nom = string.Empty,
Biographie = string.Empty,
// vérifier si les données sont corrects.
if (!this.ModelState.IsValid)
{
// Passer model en paramètre afin que
// l'utilisateur conserve sa saissie.
return this.View(model);
}
// Créer un objet Artiste avecc les paramètres.
var artiste = new Artiste
{
Nom = model.Nom,
Biographie = model.Biographie,
};
return this.View(model);
// Persister les données.
this.artisteRepository.Add(artiste);
// Renvoyer sur la page Index.
return this.RedirectToAction("Index");
}
/// <summary>
@@ -69,14 +92,37 @@ public class ArtisteController : Controller
{
var artiste = this.artisteRepository.Find(id);
var model = new AdminArtisteForm
if (artiste == null)
{
Id = artiste.IdArtiste,
Nom = artiste.Nom,
Biographie = artiste.Biographie,
return this.RedirectToAction("Index");
}
return this.View(artiste);
}
/// <summary>
/// Traitement du formulaire de modification d'un artiste.
/// </summary>
/// <param name="model">Paramètre d'un artiste.</param>
/// <returns>Redirection sur Index.</returns>
[HttpPost]
public IActionResult Edit(ArtisteEditViewModel model)
{
var artiste = new Artiste
{
IdArtiste = model.Id,
Nom = model.Nom,
Biographie = model.Biographie,
};
return this.View(model);
if (!this.ModelState.IsValid)
{
return this.View(artiste);
}
this.artisteRepository.Update(artiste);
return this.RedirectToAction("Index");
}
/// <summary>

View File

@@ -1,81 +1,113 @@
namespace Webzine.WebApplication.Areas.Administration.Controllers
namespace Webzine.WebApplication.Areas.Administration.Controllers;
using Microsoft.AspNetCore.Mvc;
using Webzine.Entity;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
/// <summary>
/// Controleur pour la gestion des styles dans l'administration du webzine.
/// </summary>
[Area("Administration")]
public class StyleController : Controller
{
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.Areas.Administration.ViewModels.Style;
/// <summary>
/// Contrôleur pour la gestion des styles dans l'administration du webzine.
/// </summary>
[Area("Administration")]
public class StyleController : Controller
{
private readonly ILogger<StyleController> logger;
private readonly IStyleRepository styleRepository;
/// <summary>
/// Initializes a new instance of the <see cref="StyleController"/> class.
/// Initialise une nouvelle instance de la classe <see cref="StyleController"/>.
/// </summary>
/// <param name="logger">Service de journalisation injecté.</param>
/// <param name="styles">Repository des styles injecté.</param>
/// <param name="logger">Service de journalisation injecte.</param>
/// <param name="styleRepository">Repository des styles injecte.</param>
public StyleController(
ILogger<StyleController> logger,
IStyleRepository styleRepository)
{
this.logger = logger;
this.logger.LogInformation("Initialisation du contrôleur StyleController.");
this.styleRepository = styleRepository;
this.logger.LogInformation("Initialisation du controleur StyleController.");
}
/// <summary>
/// Affiche la liste des styles dans la vue Index.
/// </summary>
/// <returns>La vue Index avec le ViewModel contenant la liste des styles.</returns>
/// <returns>La vue Index avec la liste des styles.</returns>
public IActionResult Index()
{
var listeStyles = this.styleRepository.FindAll().Take(10);
IEnumerable<Style> listeStyles = this.styleRepository.FindAll().Take(10);
return this.View(listeStyles);
}
/// <summary>
/// Affiche la vue de création d'un nouveau style.
/// Affiche la vue de creation d'un nouveau style.
/// </summary>
/// <returns>La vue Create pour ajouter un nouveau style.</returns>
public IActionResult Create()
{
return this.View();
var model = new StyleCreateViewModel
{
Libelle = string.Empty,
};
return this.View(model);
}
/// <summary>
/// Affiche la vue de confirmation de suppression d'un style, en récupérant les détails du style à supprimer à partir de l'identifiant fourni.
/// Cree un nouveau style.
/// </summary>
/// <param name="id">L'identifiant du style à supprimer.</param>
/// <returns>La vue de confirmation de suppression avec le ViewModel contenant les détails du style à supprimer, ou une redirection vers l'index si le style n'existe pas.</returns>
/// <param name="model">Nouveau style.</param>
/// <returns>IActionResult.</returns>
[HttpPost]
public IActionResult Create(StyleCreateViewModel model)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
var style = new Style
{
Libelle = model.Libelle,
};
this.styleRepository.Add(style);
return this.RedirectToAction("Index");
}
/// <summary>
/// Affiche la vue de confirmation de suppression d'un style.
/// </summary>
/// <param name="id">L'identifiant du style a supprimer.</param>
/// <returns>La vue de confirmation ou une redirection vers l'index si le style n'existe pas.</returns>
public IActionResult Delete(int id)
{
var style = this.styleRepository.Find(id);
var vm = new StyleDeleteViewModel
if (style == null || style.IdStyle == 0)
{
return this.RedirectToAction("Index");
}
var model = new StyleDeleteViewModel
{
IdStyle = style.IdStyle,
Libelle = style.Libelle,
};
return this.View(vm);
return this.View(model);
}
/// <summary>
/// Méthode POST pour supprimer un style.
/// Methode POST pour supprimer un style.
/// </summary>
/// <param name="model">Le style à supprimer.</param>
/// <param name="model">Le style a supprimer.</param>
/// <returns>Redirige vers la page d'index d'admin style.</returns>
[HttpPost]
public IActionResult Delete(StyleEditViewModel model)
public IActionResult Delete(StyleDeleteViewModel model)
{
var style = this.styleRepository.Find(model.IdStyle);
@@ -88,15 +120,20 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
}
/// <summary>
/// Affiche la vue d'édition d'un style existant, en récupérant les détails du style à éditer à partir de l'identifiant fourni.
/// Affiche la vue d'edition d'un style existant.
/// </summary>
/// <param name="id">L'identifiant du style à éditer.</param>
/// <returns>La vue d'édition avec le ViewModel contenant les détails du style à éditer, ou une redirection vers l'index si le style n'existe pas.</returns>
/// <param name="id">L'identifiant du style a editer.</param>
/// <returns>La vue d'edition ou une redirection vers l'index si le style n'existe pas.</returns>
[HttpGet]
public IActionResult Edit(int id)
{
var style = this.styleRepository.Find(id);
if (style == null || style.IdStyle == 0)
{
return this.RedirectToAction("Index");
}
var model = new StyleEditViewModel
{
IdStyle = style.IdStyle,
@@ -105,5 +142,29 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
return this.View(model);
}
/// <summary>
/// Met a jour un style existant.
/// </summary>
/// <param name="model">Donnees du style a modifier.</param>
/// <returns>Redirige vers la page d'index d'admin style.</returns>
[HttpPost]
public IActionResult Edit(StyleEditViewModel model)
{
if (!this.ModelState.IsValid)
{
return this.View(model);
}
var style = this.styleRepository.Find(model.IdStyle);
if (style == null)
{
return this.RedirectToAction("Index");
}
style.Libelle = model.Libelle;
this.styleRepository.Update(style);
return this.RedirectToAction("Index");
}
}

View File

@@ -0,0 +1,21 @@
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
{
using System.ComponentModel.DataAnnotations;
/// <summary>
/// ViewModel qui sert à la création d'un artiste.
/// </summary>
public class ArtisteCreateViewModel
{
/// <summary>
/// Nom de l'artiste.
/// </summary>
[Required]
public string Nom { get; set; }
/// <summary>
/// Biographie de l'artiste.
/// </summary>
public string Biographie { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Artiste
{
using System.ComponentModel.DataAnnotations;
/// <summary>
/// Permet d'éditer un Artiste.
/// </summary>
public class ArtisteEditViewModel
{
/// <summary>
/// Id de l'artiste.
/// </summary>
[Required]
public int Id { get; set; }
/// <summary>
/// Nom de l'artiste.
/// </summary>
[Required]
public string Nom { get; set; }
/// <summary>
/// Biographie de l'artiste.
/// </summary>
public string Biographie { get; set; }
}
}

View File

@@ -4,6 +4,8 @@
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
{
using System.ComponentModel.DataAnnotations;
/// <summary>
/// ViewModel pour la création d'un style en administration.
/// </summary>
@@ -12,6 +14,7 @@ namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
/// <summary>
/// Obtient ou définit le libellé du style.
/// </summary>
[Required]
public string Libelle { get; set; }
}
}

View File

@@ -4,19 +4,22 @@
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Style
{
using System.ComponentModel.DataAnnotations;
/// <summary>
/// ViewModel pour la modification d'un style en administration.
/// </summary>
public class StyleEditViewModel
{
/// <summary>
/// Obtient ou définit le libellé du style.
/// Obtient ou definit l'identifiant du style.
/// </summary>
public int IdStyle { get; set; }
/// <summary>
/// Obtient ou définit le libellé du style.
/// Obtient ou definit le libelle du style.
/// </summary>
[Required]
public string Libelle { get; set; }
}
}

View File

@@ -1,11 +1,41 @@
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.ArtisteCreateViewModel
<h1>Créer un artiste</h1>
<hr />
<form asp-action="Create" method="post">
<div class="container">
<!-- ARTISTE -->
<div class="row mb-3">
<label class="col-md-3 col-form-label">Nom de l'artiste<span class="text-danger">*</span></label>
<div class="col-md-9">
<input asp-for="Nom" class="form-control" />
</div>
</div>
<partial name="_Form" />
<!-- BIOGRAPHIE -->
<div class="row mb-3">
<label class="col-md-3 col-form-label">Biographie</label>
<div class="col-md-9">
<textarea asp-for="Biographie" class="form-control" rows="5"></textarea>
</div>
</div>
<!-- BOUTONS -->
<div class="row mt-4">
<div class="col-md-9 offset-md-3">
<button type="submit" class="btn btn-primary me-2">
Sauvegarder
</button>
</div>
</div>
<br />
<br />
<a asp-action="Index"
class="btn text-primary">
Retour à l'administration des artistes
</a>
</div>
</form>

View File

@@ -1,4 +1,4 @@
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
@model Webzine.Entity.Artiste
<h1>Editer un artiste</h1>
@@ -6,7 +6,7 @@
<form asp-action="Edit" method="post">
<input type="hidden" asp-for="Id"/>
<input type="hidden" asp-for="IdArtiste"/>
<partial name="_Form" />

View File

@@ -1,4 +1,4 @@
@model Webzine.WebApplication.Areas.Administration.ViewModels.Artiste.AdminArtisteForm
@model Webzine.Entity.Artiste
<div class="container">
<!-- ARTISTE -->
@@ -17,8 +17,6 @@
</div>
</div>
<!-- BOUTONS -->
<div class="row mt-4">
<div class="col-md-9 offset-md-3">

View File

@@ -64,6 +64,7 @@ namespace Webzine.WebApplication.Controllers
NbLikes = titre.NbLikes,
UrlJaquette = titre.UrlJaquette,
UrlEcoute = titre.UrlEcoute,
UrlEmbedEcoute = BuildSpotifyEmbedUrl(titre.UrlEcoute),
ArtisteNom = titre.Artiste.Nom,
Styles = titre.Styles,
Commentaires = titre.Commentaires,
@@ -169,5 +170,23 @@ namespace Webzine.WebApplication.Controllers
Duree = titre.Duree,
};
}
/// <summary>
///
/// </summary>
/// <param name="urlEcoute"></param>
/// <returns></returns>
private static string? BuildSpotifyEmbedUrl(string? urlEcoute)
{
if (string.IsNullOrWhiteSpace(urlEcoute))
{
return null;
}
var trackId = urlEcoute.Split('/').LastOrDefault();
return string.IsNullOrWhiteSpace(trackId)
? null
: $"https://open.spotify.com/embed/track/{trackId}";
}
}
}

View File

@@ -38,6 +38,7 @@ try
// En fonction de la configuration, utilise soit les repositories basés sur une base de données, soit les repositories basés sur des listes locales.
var repositoryType = builder.Configuration.GetValue<RepositoryType>("Repository");
var seederType = builder.Configuration.GetValue<SeederType>("Seeder");
var shouldSeed = args.Contains("--seed");
if (repositoryType == RepositoryType.Db)
{
if (builder.Environment.IsProduction())
@@ -77,11 +78,22 @@ try
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
if (shouldSeed)
{
db.Database.EnsureDeleted();
db.Database.EnsureCreated();
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
if (seederType == SeederType.Local)
{
repo.SeedBaseDeDonnees();
}
else if (seederType == SeederType.Spotify)
{
// Seed à l'aide de l'API Spotify.
}
}
}
}
else
{

View File

@@ -18,6 +18,26 @@
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"http-seed": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5038",
"commandLineArgs": "--seed",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https-seed": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7095;http://localhost:5038",
"commandLineArgs": "--seed",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -42,6 +42,11 @@ public class TitreContent
/// </summary>
public string UrlEcoute { get; set; }
/// <summary>
/// Définit l'url du lecteur embarqué du titre.
/// </summary>
public string? UrlEmbedEcoute { get; set; }
/// <summary>
/// Définit le nom de l'artiste associé au titre.
/// </summary>

View File

@@ -61,7 +61,7 @@
</ul>
<!-- Barre de recherche -->
<form class="d-flex" asp-controller="Recherche" asp-action="Index" method="get">
<form class="d-flex" asp-area="" asp-controller="Recherche" asp-action="Index" method="get">
<div class="input-group">
<div class="form-outline">
<input class="form-control me-2"

View File

@@ -93,14 +93,28 @@
</div>
<!-- LECTEUR -->
@if (!string.IsNullOrEmpty(Model.Details.UrlEcoute))
@if (!string.IsNullOrEmpty(Model.Details.UrlEmbedEcoute))
{
<div class="mt-4">
<iframe width="100%" height="315"
src="@Model.Details.UrlEcoute"
title="Lecteur"
allowfullscreen>
<h4 class="mb-3">Ecouter le titre</h4>
<iframe src="@Model.Details.UrlEmbedEcoute"
width="100%"
height="152"
title="Lecteur Spotify"
frameborder="0"
allowfullscreen
allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
loading="lazy">
</iframe>
@if (!string.IsNullOrEmpty(Model.Details.UrlEcoute))
{
<p class="mt-2 mb-0">
<a href="@Model.Details.UrlEcoute" target="_blank" rel="noopener noreferrer">
Ouvrir dans Spotify
</a>
</p>
}
</div>
}

View File

@@ -1,4 +1,8 @@
{
"Seeder": "Local",
"Repository": "Db"
"Seeder": "Spotify",
"Repository": "Db",
"SpotifySeeder": {
"ClientId": "754247cf73e047bf9d6acf44977b6c4a",
"ClientSecret": "0e674c5ac1c249f1af711fb08a919a02"
}
}

View File

@@ -1,4 +1,8 @@
{
"Seeder": "Local",
"Repository": "Db"
"Repository": "Db",
"SpotifySeeder": {
"ClientId": "",
"ClientSecret": ""
}
}

View File

@@ -13,5 +13,15 @@
"SqliteConnection": "Data Source=Data/webzine.sqlite",
"PostGreSQLConnection": "Host=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db"
},
"SpotifySeeder": {
"ClientId": "754247cf73e047bf9d6acf44977b6c4a",
"ClientSecret": "0e674c5ac1c249f1af711fb08a919a02",
"Market": "FR",
"Genres": [ "rock", "pop", "jazz", "hip hop", "electronic", "metal" ],
"ArtistsPerGenre": 4,
"AlbumsPerArtist": 2,
"TracksPerAlbum": 4,
"MaxCommentsPerTrack": 3
},
"AllowedHosts": "*"
}