#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> /// </summary>
/// <param name="artiste">L'artiste à mettre à jour.</param> /// <param name="artiste">L'artiste à mettre à jour.</param>
void Update(Artiste artiste); 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 namespace Webzine.Repository
{ {
using System.Data.Common;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -156,5 +154,23 @@ namespace Webzine.Repository
throw; 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"); 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); 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 var artistes = this.artisteRepository.Search(mot);
.FindAll()
.Where(a => a.Nom.ToLower().Contains(mot.ToLower()))
.ToList();
var vm = new RechercheIndexViewModel var vm = new RechercheIndexViewModel
{ {

View File

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