#175 Correction des repository : First remplacé par FirstOrDefault. Ajout de la documentation manquante. Les return Model() vides sont supprimés. La gestion d'erreurs est optimisée.

This commit is contained in:
josephine.vetu
2026-04-01 11:43:01 +02:00
parent 19b920ba4e
commit 03cc02b6f2
11 changed files with 54 additions and 110 deletions

View File

@@ -15,7 +15,6 @@ namespace Webzine.Repository
/// <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
{
@@ -25,7 +24,7 @@ namespace Webzine.Repository
/// <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.
/// Gère les opérations liées aux commentaires en utilisant une source de données locale (en mémoire).
/// </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>
@@ -47,22 +46,10 @@ namespace Webzine.Repository
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;
return this.dataStore.Commentaires.FirstOrDefault(c => c.IdCommentaire == idCommentaire);
}
/// <inheritdoc/>
@@ -74,27 +61,13 @@ namespace Webzine.Repository
}
/// <inheritdoc/>
public IEnumerable<Commentaire> FindCommentaires(int offset, int limit)
public IEnumerable<Commentaire> Paginate(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();
}
}
}