Merge branch 'dev' into j3/refactor/appsetting

This commit is contained in:
c.bobin
2026-03-31 15:40:43 +02:00
10 changed files with 118 additions and 119 deletions

View File

@@ -8,54 +8,40 @@ namespace Webzine.WebApplication.Controllers
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
[Route("recherche")]
public class RechercheController : Controller
{
private readonly ILogger<RechercheController> logger;
private readonly ITitreRepository titreRepository;
private readonly IArtisteRepository artisteRepository;
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
public RechercheController(
ILogger<RechercheController> logger,
ITitreRepository titreRepository,
IArtisteRepository artisteRepository)
{
this.logger = logger;
this.titreRepository = titreRepository;
this.artisteRepository = artisteRepository;
}
[HttpPost("")]
/// <summary>
/// Affichage de la page Recherche depuis le header de l'app.
/// </summary>
/// <param name="mot">Nom d'artiste ou de titre.</param>
/// <returns>Page de recherche avec les résultats.</returns>
public IActionResult Index(string mot)
{
// Logger la recherche.
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
var titres = this.titreRepository.Search(mot)
.Concat(this.titreRepository.SearchByStyle(mot))
.DistinctBy(t => t.IdTitre)
.OrderBy(t => t.Libelle)
.Select(t => new TitreStyleItem
{
IdTitre = t.IdTitre,
Libelle = t.Libelle,
ArtisteNom = t.Artiste?.Nom,
UrlJaquette = t.UrlJaquette,
Duree = t.Duree,
})
.ToList();
// Recherche des titres.
var titres = this.titreRepository.Search(mot);
var artistes = this.titreRepository.FindAll()
.Select(t => t.Artiste)
.Where(a => a != null
&& !string.IsNullOrWhiteSpace(a.Nom)
&& !string.IsNullOrWhiteSpace(mot)
&& a.Nom.Contains(mot, StringComparison.OrdinalIgnoreCase))
.DistinctBy(a => a!.IdArtiste)
.OrderBy(a => a!.Nom)
.Select(a => new RechercheArtisteItem
{
Nom = a!.Nom,
NombreDeTitres = a.Titres?.Count ?? 0,
})
.ToList();
// Recherche des artistes.
var artistes = this.artisteRepository.Search(mot);
// Paramètres a retourner à la vue.
var vm = new RechercheIndexViewModel
{
Mot = mot,

View File

@@ -1,17 +0,0 @@
namespace Webzine.WebApplication.ViewModels.Recherche;
/// <summary>
/// ViewModel pour afficher un artiste dans les resultats de recherche.
/// </summary>
public class RechercheArtisteItem
{
/// <summary>
/// Nom de l'artiste.
/// </summary>
public string? Nom { get; set; }
/// <summary>
/// Nombre de titres associes a l'artiste.
/// </summary>
public int NombreDeTitres { get; set; }
}

View File

@@ -1,24 +1,25 @@
namespace Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
/// <summary>
/// ViewModel pour afficher les resultats de recherche d'artistes et de titres.
/// </summary>
public class RechercheIndexViewModel
namespace Webzine.WebApplication.ViewModels.Recherche
{
/// <summary>
/// Mot saisi dans le formulaire.
/// </summary>
public string? Mot { get; set; }
using Webzine.Entity;
/// <summary>
/// Artistes trouves.
/// ViewModel pour afficher les resultats de recherche d'artistes et de titres.
/// </summary>
public List<RechercheArtisteItem> Artistes { get; set; } = new ();
public class RechercheIndexViewModel
{
/// <summary>
/// Mot saisi dans le formulaire.
/// </summary>
public string? Mot { get; set; }
/// <summary>
/// Titres trouves.
/// </summary>
public List<TitreStyleItem> Titres { get; set; } = new ();
/// <summary>
/// Artistes trouves.
/// </summary>
public IEnumerable<Artiste> Artistes { get; set; } = new List<Artiste>();
/// <summary>
/// Titres trouves.
/// </summary>
public IEnumerable<Titre> Titres { get; set; } = new List<Titre>();
}
}

View File

@@ -10,74 +10,65 @@
<h1 class="mb-4">Resultats pour "@Model.Mot"</h1>
<hr />
<h2 class="h4 mt-4">Artistes</h2>
@if (string.IsNullOrWhiteSpace(Model.Mot))
@if (!Model.Artistes.Any())
{
<div class="alert alert-info">
Saisissez un mot-cle pour lancer une recherche.
<p>Aucun artiste n'a été trouvé.</p>
</div>
}
else if (!Model.Artistes.Any() && !Model.Titres.Any())
@foreach (var artiste in Model.Artistes)
{
<div class="my-3">
<a asp-controller="Artiste"
asp-action="Index"
asp-route-nom="@artiste.Nom">
@artiste.Nom
</a>
<span class="text-muted">(@artiste.Titres.Count titre(s))</span>
</div>
}
<h2 class="h4 mt-4">Titres</h2>
@if (!Model.Titres.Any())
{
<div class="alert alert-info">
Aucun artiste ni titre ne correspond a votre recherche.
<p>Aucun titre n'a été trouvé.</p>
</div>
}
else
{
@if (Model.Artistes.Any())
{
<h2 class="h4 mt-4">Artistes</h2>
@foreach (var artiste in Model.Artistes)
{
<div class="my-3">
@foreach (var titre in Model.Titres)
{
<div class="d-flex align-items-start my-3">
<a asp-controller="Titre"
asp-action="Details"
asp-route-id="@titre.IdTitre"
class="me-3 text-black">
<img src="@titre.UrlJaquette" alt="@titre.Libelle" width="70" height="70" class="object-fit-cover" loading="lazy" />
</a>
<div class="justify-content-center d-flex flex-column">
<div>
<a asp-controller="Artiste"
asp-action="Index"
asp-route-nom="@artiste.Nom">
@artiste.Nom
asp-route-nom="@titre.Artiste.Nom">
@titre.Artiste.Nom
</a>
<span class="text-muted">(@artiste.NombreDeTitres titre(s))</span>
</div>
}
}
@if (Model.Titres.Any())
{
<h2 class="h4 mt-4">Titres</h2>
@foreach (var titre in Model.Titres)
{
<div class="d-flex align-items-start my-3">
-
<a asp-controller="Titre"
asp-action="Details"
asp-route-id="@titre.IdTitre"
class="me-3 text-black">
<img src="@titre.UrlJaquette" alt="@titre.Libelle" width="70" height="70" class="object-fit-cover" loading="lazy"/>
asp-route-id="@titre.IdTitre">
@titre.Libelle
</a>
<div class="justify-content-center d-flex flex-column">
<div>
<a asp-controller="Artiste"
asp-action="Index"
asp-route-nom="@titre.ArtisteNom">
@titre.ArtisteNom
</a>
-
<a asp-controller="Titre"
asp-action="Details"
asp-route-id="@titre.IdTitre">
@titre.Libelle
</a>
</div>
<div>
Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss")
</div>
</div>
</div>
}
}
<div>
Duree : @TimeSpan.FromSeconds(titre.Duree).ToString(@"mm\:ss")
</div>
</div>
</div>
}
</div>
</div>

View File

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