Merge branch 'dev' into j1/feat/page_contact
This commit is contained in:
54
Webzine.Entity/Fixtures/ArtisteFactory.cs
Normal file
54
Webzine.Entity/Fixtures/ArtisteFactory.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Bogus;
|
||||
|
||||
namespace Webzine.Entity.Fixtures
|
||||
{
|
||||
/// <summary>
|
||||
/// Factory pour générer des artistes avec des titres associés, à l'aide de la bibliothèque Bogus.
|
||||
///
|
||||
/// </summary>
|
||||
public class ArtisteFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Récupère un artiste par son nom, en générant des données fictives pour ses titres associés.
|
||||
/// </summary>
|
||||
/// <param name="nom"></param>
|
||||
/// <returns></returns>
|
||||
public static Artiste SeedArtisteByName(string nom)
|
||||
{
|
||||
// On définit nos albums "bouchonnés"
|
||||
var albumsData = new[]
|
||||
{
|
||||
new { Nom = "Bohemian Rhapsody", Image = "https://upload.wikimedia.org/wikipedia/en/9/9f/Bohemian_Rhapsody.png" },
|
||||
new { Nom = "Born This Way", Image = "https://static.wikia.nocookie.net/ladygaga/images/2/2d/BornThisWay-DeluxeEdition.jpg/revision/latest/scale-to-width-down/3500?cb=20111120030308" }
|
||||
};
|
||||
|
||||
var faker = new Bogus.Faker("fr");
|
||||
var tousLesTitres = new List<Titre>();
|
||||
|
||||
// Pour chaque album, on génère un paquet de titres
|
||||
foreach (var album in albumsData)
|
||||
{
|
||||
var nombreDeTitres = faker.Random.Number(3, 6);
|
||||
|
||||
var titresDeLalbum = new Faker<Titre>("fr")
|
||||
.RuleFor(t => t.IdTitre, f => f.IndexFaker + 1 + tousLesTitres.Count)
|
||||
.RuleFor(t => t.UrlJaquette, _ => album.Image)
|
||||
.RuleFor(t => t.Album, _ => album.Nom)
|
||||
.RuleFor(t => t.Duree, f => f.Random.Number(90, 180))
|
||||
.RuleFor(t => t.Libelle, f => f.Music.Genre() + " - " + f.Commerce.ProductName())
|
||||
.Generate(nombreDeTitres);
|
||||
|
||||
tousLesTitres.AddRange(titresDeLalbum);
|
||||
}
|
||||
|
||||
// On crée l'artiste final
|
||||
var artisteFaker = new Faker<Artiste>("fr")
|
||||
.RuleFor(a => a.IdArtiste, f => f.IndexFaker + 1)
|
||||
.RuleFor(a => a.Nom, _ => nom)
|
||||
.RuleFor(a => a.Biographie, f => f.Lorem.Paragraphs(2))
|
||||
.RuleFor(a => a.Titres, _ => tousLesTitres);
|
||||
|
||||
return artisteFaker.Generate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="35.6.5" />
|
||||
<PackageReference Include="Faker.Net" Version="2.0.163" />
|
||||
<PackageReference Include="NLog" Version="6.1.1" />
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||
|
||||
@@ -5,9 +5,18 @@ namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
public class AccueilController : Microsoft.AspNetCore.Mvc.Controller
|
||||
{
|
||||
// Injection du logger via le constructeur
|
||||
private readonly ILogger<AccueilController> _logger;
|
||||
|
||||
public AccueilController(ILogger<AccueilController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// GET: AccueilController
|
||||
public ActionResult Index()
|
||||
{
|
||||
_logger.LogInformation("Arrivée sur la page d'accueil");
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
54
Webzine.WebApplication/Controllers/ArtisteController.cs
Normal file
54
Webzine.WebApplication/Controllers/ArtisteController.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.WebApplication.ViewModels;
|
||||
|
||||
namespace Webzine.WebApplication.Controllers
|
||||
{
|
||||
public class ArtisteController : Controller
|
||||
{
|
||||
// Injection du logger via le constructeur
|
||||
private readonly ILogger<ArtisteController> _logger;
|
||||
|
||||
public ArtisteController(ILogger<ArtisteController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prend en paramètre le nom de l'artiste (ex: "fatal-bazooka"), utilise la factory pour trouver l'artiste correspondant, et affiche sa page dédiée.
|
||||
/// </summary>
|
||||
/// <param name="nom"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/artiste/{nom}")]
|
||||
public IActionResult Index(string nom)
|
||||
{
|
||||
_logger.LogInformation("Tentative d'accès à l'artiste avec le nom : {NomArtiste}", nom);
|
||||
|
||||
if (string.IsNullOrEmpty(nom)) return RedirectToAction("Index", "Accueil");
|
||||
|
||||
// On transforme "fatal-bazooka" en "Fatal Bazooka" pour la factory
|
||||
string nomPropre = System.Globalization.CultureInfo.CurrentCulture.TextInfo
|
||||
.ToTitleCase(nom.Replace("-", " "));
|
||||
|
||||
// On appelle la factory pour obtenir l'artiste unique
|
||||
var artiste = ArtisteFactory.SeedArtisteByName(nomPropre);
|
||||
|
||||
if (artiste == null)
|
||||
{
|
||||
_logger.LogWarning("Artiste non trouvé pour le nom : {NomArtiste}", nomPropre);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_logger.LogInformation("Artiste trouvé : {NomArtiste}", nom);
|
||||
|
||||
// On remplit le ViewModel
|
||||
var viewModel = new ArtisteModel
|
||||
{
|
||||
Artiste = artiste,
|
||||
Titres = artiste.Titres
|
||||
};
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Webzine.WebApplication/ViewModels/ArtisteModel.cs
Normal file
17
Webzine.WebApplication/ViewModels/ArtisteModel.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Webzine.Entity;
|
||||
|
||||
namespace Webzine.WebApplication.ViewModels
|
||||
{
|
||||
public class ArtisteModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Artiste dont on affiche les détails.
|
||||
/// </summary>
|
||||
public Artiste Artiste { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Liste des titres de l'artiste.
|
||||
/// </summary>
|
||||
public List<Titre> Titres { get; set; }
|
||||
}
|
||||
}
|
||||
70
Webzine.WebApplication/Views/Artiste/Index.cshtml
Normal file
70
Webzine.WebApplication/Views/Artiste/Index.cshtml
Normal file
@@ -0,0 +1,70 @@
|
||||
@model Webzine.WebApplication.ViewModels.ArtisteModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Artiste";
|
||||
}
|
||||
|
||||
|
||||
<div class="container">
|
||||
<h1>@Model.Artiste.Nom</h1>
|
||||
|
||||
<hr class="mb-5" />
|
||||
|
||||
<p class="lead">@Model.Artiste.Biographie</p>
|
||||
|
||||
<h2 class="mt-5 mb-4">Albums</h2>
|
||||
<hr class="mb-5" />
|
||||
|
||||
@* On groupe les titres par nom d'album *@
|
||||
@{
|
||||
var albumsGroupes = Model.Titres
|
||||
.OrderBy(t => t.Libelle) // Trie les titres par ordre alphabétique au sein de chaque groupe futur
|
||||
.GroupBy(t => t.Album) // Groupe par nom d'album
|
||||
.OrderBy(g => g.Key); // Trie les albums par ordre alphabétique (la clé du groupe)
|
||||
}
|
||||
|
||||
@foreach (var groupe in albumsGroupes)
|
||||
{
|
||||
// On récupère le premier titre du groupe pour afficher l'image de l'album
|
||||
var premierTitre = groupe.First();
|
||||
|
||||
<div class="row mb-5 align-items-start">
|
||||
<div class="col-md-3 mb-3">
|
||||
<img src="@premierTitre.UrlJaquette"
|
||||
class="img-fluid shadow-sm rounded border"
|
||||
alt="Pochette de @groupe.Key" />
|
||||
</div>
|
||||
|
||||
<div class="col-md-9">
|
||||
<h3 class="h4 pb-2">@groupe.Key</h3>
|
||||
|
||||
<table class="table table-hover table-sm mt-3">
|
||||
<thead class="text-muted">
|
||||
<tr>
|
||||
<th style="width: 80px">Durée</th>
|
||||
<th>Titre</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var titre in groupe)
|
||||
{
|
||||
// Conversion des secondes en format MM:SS
|
||||
var minutes = titre.Duree / 60;
|
||||
var secondes = titre.Duree % 60;
|
||||
var dureeFormatee = $"{minutes}:{secondes:D2}";
|
||||
|
||||
<tr>
|
||||
<td class="text-secondary font-monospace">@dureeFormatee</td>
|
||||
<td>
|
||||
<span class="text-primary fw-bold" style="cursor:pointer">
|
||||
@titre.Libelle
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@@ -7,4 +7,7 @@
|
||||
<View_SelectedScaffolderID>RazorViewEmptyScaffolder</View_SelectedScaffolderID>
|
||||
<View_SelectedScaffolderCategoryPath>root/Common/MVC/View</View_SelectedScaffolderCategoryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user