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