namespace Webzine.Repository; using Microsoft.Extensions.Logging; using Webzine.Entity; using Webzine.Repository.Contracts; /// /// Classe qui implémente le repository pour les titres en utilisant une liste locale comme source de données. /// public class LocalTitreRepository : ITitreRepository { private readonly ILogger logger; private readonly InMemoryDataStore dataStore; /// /// Initializes a new instance of the class. /// /// Le service de journalisation injecté pour suivre les opérations du repository. /// La liste de titres à utiliser comme source de données pour le repository. public LocalTitreRepository(ILogger logger, InMemoryDataStore dataStore) { this.logger = logger; this.dataStore = dataStore; this.logger.LogDebug(1, "NLog injecté dans LocalTitreRepository"); } /// public void Add(Titre titre) { throw new NotSupportedException("Mode local"); } /// public int Count() { var count = this.dataStore.Titres.Count(); return count; } /// public void Delete(Titre titre) { throw new NotSupportedException("Mode Local"); } /// public IEnumerable FindTitres(int offset, int limit) { return this.dataStore.Titres .OrderByDescending(t => t.DateCreation) .Skip(offset) .Take(limit); } /// public void IncrementNbLectures(Titre titre) { titre.NbLectures++; } /// public void IncrementNbLikes(Titre titre) { titre.NbLikes++; } /// public IEnumerable Search(string mot) { return this.dataStore.Titres .Where(t => t.Libelle != null && t.Libelle.Contains(mot)); } /// public Titre Find(int idTitre) { return this.dataStore.Titres .First(t => t.IdTitre == idTitre); } /// public IEnumerable FindAll() { return this.dataStore.Titres; } /// public IEnumerable SearchByStyle(string libelle) { return this.dataStore.Titres .Where(t => t.Styles.Any(s => s.Libelle == libelle)); } /// public void Update(Titre titre) { throw new NotSupportedException("Mode local"); } }