Ajout de l'implémentation du Repo pour la base de données afin d'afficher les titres sur la page d'accueil.

This commit is contained in:
Loic Masi
2026-03-26 12:00:44 +01:00
parent 9801eb555f
commit 23d46154db
12 changed files with 279 additions and 103 deletions

View File

@@ -1,63 +1,68 @@
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
// <copyright file="RechercheController.cs" company=" Equipe 1 - ">
// Copyright (c) Equipe 1 - . All rights reserved.
// </copyright>
namespace Webzine.WebApplication.Controllers;
[Route("recherche")]
public class RechercheController : Controller
namespace Webzine.WebApplication.Controllers
{
private readonly ILogger<RechercheController> _logger;
private readonly ITitreRepository _titreRepository;
using Microsoft.AspNetCore.Mvc;
using Webzine.Repository.Contracts;
using Webzine.WebApplication.ViewModels.Recherche;
using Webzine.WebApplication.ViewModels.Titre;
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
[Route("recherche")]
public class RechercheController : Controller
{
this._logger = logger;
this._titreRepository = titreRepository;
}
private readonly ILogger<RechercheController> logger;
private readonly ITitreRepository titreRepository;
[HttpPost("")]
public IActionResult Index(string mot)
{
this._logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
var titres = _titreRepository.Search(mot)
.Concat(_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();
var artistes = _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();
var vm = new RechercheIndexViewModel
public RechercheController(ILogger<RechercheController> logger, ITitreRepository titreRepository)
{
Mot = mot,
Artistes = artistes,
Titres = titres
};
this.logger = logger;
this.titreRepository = titreRepository;
}
return View(vm);
[HttpPost("")]
public IActionResult Index(string mot)
{
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();
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();
var vm = new RechercheIndexViewModel
{
Mot = mot,
Artistes = artistes,
Titres = titres,
};
return this.View(vm);
}
}
}