Files
webzine/Webzine.Repository/LocalCommentaireRepository.cs
josephine.vetu b2dc449adb add TODO
2026-04-01 11:55:27 +02:00

100 lines
3.4 KiB
C#

// <copyright file="LocalCommentaireRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
using Webzine.Entity;
using Webzine.Repository.Contracts;
/// <summary>
/// Initialise une classe <see cref="LocalCommentaireRepository"/> qui implémente l'interface <see cref="ICommentaireRepository"/> pour gérer les opérations liées aux commentaires.
/// Utilise <see cref="ICommentaireRepository"/> en injection de dépendances.
/// </summary>
public class LocalCommentaireRepository : ICommentaireRepository
{
private readonly ILogger<LocalCommentaireRepository> logger;
private readonly InMemoryDataStore dataStore;
/// <summary>
/// Initializes a new instance of the <see cref="LocalCommentaireRepository"/> class.
/// Initialise une nouvelle instance du <see cref="LocalCommentaireRepository"/> .
/// Est liée à un magasin de données en mémoire et utilise un logger pour enregistrer les opérations.
/// </summary>
/// <param name="dataStore">Le magasin de données en mémoire. Ne peut pas être null.</param>
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
public LocalCommentaireRepository(InMemoryDataStore dataStore, ILogger<LocalCommentaireRepository> logger)
{
this.logger = logger;
this.dataStore = dataStore;
}
/// <inheritdoc/>
public void Add(Commentaire commentaire)
{
throw new NotSupportedException("Mode Local"); // TODO à implémenter
}
/// <inheritdoc/>
public void Delete(Commentaire commentaire)
{
throw new NotSupportedException("Mode Local");
}
/// <inheritdoc/>
public int Count()
{
return this.dataStore.Commentaires.Count;
}
/// <inheritdoc/>
public Commentaire Find(int idCommentaire)
{
var commentaire = this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire);
if (commentaire == null)
{
return new Commentaire();
}
return commentaire;
}
/// <inheritdoc/>
public IEnumerable<Commentaire> FindAll()
{
return this.dataStore.Commentaires
.OrderByDescending(c => c.DateCreation)
.ToList();
}
/// <inheritdoc/>
public IEnumerable<Commentaire> FindCommentaires(int offset, int limit)
{
if (offset < 0 || limit <= 0)
{
return Enumerable.Empty<Commentaire>();
}
return this.dataStore.Commentaires
.OrderByDescending(c => c.DateCreation)
.Skip(offset)
.Take(limit)
.ToList();
}
/// <inheritdoc/>
public IEnumerable<Commentaire> FindByIdTitre(int idTitre)
{
return this.dataStore.Commentaires
.Where(c => c.Titre != null && c.Titre.IdTitre == idTitre)
.OrderByDescending(c => c.DateCreation)
.ToList();
}
}
}