Refacto StyleCop

This commit is contained in:
Loic Masi
2026-03-26 14:33:31 +01:00
parent 2b14d4bf24
commit 49bf4a024b
12 changed files with 227 additions and 374 deletions

View File

@@ -1,4 +1,8 @@
namespace Webzine.Repository
// <copyright file="LocalArtisteRepository.cs" company="PlaceholderCompany">
// Copyright (c) PlaceholderCompany. All rights reserved.
// </copyright>
namespace Webzine.Repository
{
using Microsoft.Extensions.Logging;
using Webzine.Entity;
@@ -10,8 +14,8 @@
/// </summary>
public class LocalArtisteRepository : IArtisteRepository
{
private readonly ILogger<LocalArtisteRepository> _logger;
private readonly List<Artiste> _artistes;
private readonly ILogger<LocalArtisteRepository> logger;
private readonly List<Artiste> artistes;
/// <summary>
/// Initializes a new instance of the <see cref="LocalArtisteRepository"/> class.
@@ -21,8 +25,8 @@
/// <param name="logger">Le logger à utiliser pour enregistrer les messages de journalisation. Ne peut pas être null.</param>
public LocalArtisteRepository(List<Artiste> artistes, ILogger<LocalArtisteRepository> logger)
{
this._logger = logger;
this._artistes = artistes;
this.logger = logger;
this.artistes = artistes;
}
/// <inheritdoc/>
@@ -30,18 +34,18 @@
{
try
{
if (this._artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
if (this.artistes.Any(a => a.IdArtiste == artiste.IdArtiste))
{
this._logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
this.logger.LogWarning("Un artiste avec l'ID {Id} existe déjà. L'ajout est ignoré.", artiste.IdArtiste);
return;
}
this._artistes.Add(artiste);
this._logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
this.artistes.Add(artiste);
this.logger.LogInformation("Artiste ajouté : {Nom}", artiste.Nom);
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
this.logger.LogError(ex, "Erreur lors de l'ajout de l'artiste : {Nom}", artiste?.Nom);
throw;
}
}
@@ -51,12 +55,12 @@
{
try
{
this._artistes.Remove(artiste);
this._logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
this.artistes.Remove(artiste);
this.logger.LogInformation("Artiste supprimé : {Nom}", artiste.Nom);
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
this.logger.LogError(ex, "Erreur lors de la suppression de l'artiste : {Nom}", artiste.Nom);
throw;
}
}
@@ -66,12 +70,12 @@
{
try
{
Artiste artiste = this._artistes.First(a => a.IdArtiste == id);
Artiste artiste = this.artistes.First(a => a.IdArtiste == id);
return artiste;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec ID: {Id}", id);
throw;
}
}
@@ -81,22 +85,21 @@
{
try
{
Artiste artiste = this._artistes.First(a => a.Nom == nom);
Artiste artiste = this.artistes.First(a => a.Nom == nom);
return artiste;
}
catch (Exception ex)
{
this._logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
throw;
this.logger.LogError(ex, "Erreur lors de la recherche de l'artiste avec le nom: {Nom}", nom);
throw;
}
}
/// <inheritdoc/>
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
public IEnumerable<Artiste> FindAll()
{
return this._artistes;
return this.artistes;
}
/// <inheritdoc/>
@@ -104,7 +107,7 @@
{
try
{
var artisteToUpdate = this._artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
var artisteToUpdate = this.artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
if (artisteToUpdate != null)
{
@@ -112,17 +115,17 @@
artisteToUpdate.Biographie = artiste.Biographie;
artisteToUpdate.Titres = artiste.Titres;
this._logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
this.logger.LogInformation("Artiste {Id} mis à jour avec succès.", artiste.IdArtiste);
}
else
{
this._logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
this.logger.LogWarning("Mise à jour impossible : l'artiste avec l'ID {Id} n'existe pas.", artiste.IdArtiste);
throw new KeyNotFoundException($"L'artiste {artiste.IdArtiste} est introuvable.");
}
}
catch (Exception ex)
{
this._logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
this.logger.LogError(ex, "Une erreur est survenue lors de la mise à jour de l'artiste {Id}.", artiste.IdArtiste);
throw;
}
}