#154 : Déplacement de la recherche des artistes dans les RepositoryArtiste.

This commit is contained in:
Loic Masi
2026-03-31 13:30:47 +02:00
parent 6f009fcc3d
commit e5ecf75f49
5 changed files with 37 additions and 9 deletions

View File

@@ -44,5 +44,12 @@ namespace Webzine.Repository.Contracts
/// </summary>
/// <param name="artiste">L'artiste à mettre à jour.</param>
void Update(Artiste artiste);
/// <summary>
/// Récupérer une liste d'artiste à partir d'une recherche.
/// </summary>
/// <param name="nom">Nom de l'artiste.</param>
/// <returns>IEnumarble<Artiste> qui contient la chaine de caractere.</returns>
IEnumerable<Artiste> Search(string nom);
}
}

View File

@@ -4,8 +4,6 @@
namespace Webzine.Repository
{
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@@ -156,5 +154,23 @@ namespace Webzine.Repository
throw;
}
}
/// <inheritdoc/>
public IEnumerable<Artiste> Search(string mot)
{
try
{
var artiste = this.context.Artistes
.Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
.Include(t => t.Titres)
.AsNoTracking()
.ToList();
return artiste;
}
catch (Exception ex)
{
throw new Exception("Erreur lors de la recherche d'artiste {error}", ex);
}
}
}
}

View File

@@ -85,5 +85,13 @@ namespace Webzine.Repository
{
throw new NotSupportedException("Mode Local");
}
/// <inheritdoc/>
public IEnumerable<Artiste> Search(string mot)
{
return this.dataStore.Artistes
.Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
.ToList();
}
}
}

View File

@@ -29,12 +29,9 @@ namespace Webzine.WebApplication.Controllers
{
this.logger.LogInformation("Recherche artistes/titres pour le mot : {Mot}.", mot);
var titres = this.titreRepository.Search(mot).ToList();
var titres = this.titreRepository.Search(mot);
var artistes = this.artisteRepository
.FindAll()
.Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
.ToList();
var artistes = this.artisteRepository.Search(mot);
var vm = new RechercheIndexViewModel
{

View File

@@ -14,11 +14,11 @@ namespace Webzine.WebApplication.ViewModels.Recherche
/// <summary>
/// Artistes trouves.
/// </summary>
public List<Artiste> Artistes { get; set; } = new ();
public IEnumerable<Artiste> Artistes { get; set; } = new List<Artiste>();
/// <summary>
/// Titres trouves.
/// </summary>
public List<Titre> Titres { get; set; } = new ();
public IEnumerable<Titre> Titres { get; set; } = new List<Titre>();
}
}