#184 Implémentation des méthodes des repo en local. Suprression des exceptions de non implementation.

This commit is contained in:
josephine.vetu
2026-04-01 16:48:18 +02:00
parent 286397cb9e
commit afc9f1bdb4
4 changed files with 42 additions and 17 deletions

View File

@@ -36,21 +36,19 @@ namespace Webzine.Repository
/// <inheritdoc/> /// <inheritdoc/>
public void Add(Artiste artiste) public void Add(Artiste artiste)
{ {
throw new NotSupportedException("Mode Local"); // TODO à implémenter this.dataStore.Artistes.Add(artiste);
} }
/// <inheritdoc/> /// <inheritdoc/>
public void Delete(Artiste artiste) public void Delete(Artiste artiste)
{ {
throw new NotSupportedException("Mode Local"); this.dataStore.Artistes.Remove(artiste);
} }
/// <inheritdoc/> /// <inheritdoc/>
public Artiste Find(int id) public Artiste Find(int id)
{ {
var artiste = this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id); return this.dataStore.Artistes.SingleOrDefault(a => a.IdArtiste == id);
return artiste;
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -69,7 +67,6 @@ namespace Webzine.Repository
} }
/// <inheritdoc/> /// <inheritdoc/>
/// La liste retournée est une copie de la liste interne, donc elle ne peut être nulle.
public IEnumerable<Artiste> FindAll() public IEnumerable<Artiste> FindAll()
{ {
return this.dataStore.Artistes; return this.dataStore.Artistes;
@@ -78,7 +75,16 @@ namespace Webzine.Repository
/// <inheritdoc/> /// <inheritdoc/>
public void Update(Artiste artiste) public void Update(Artiste artiste)
{ {
throw new NotSupportedException("Mode Local"); var stored = this.dataStore.Artistes.FirstOrDefault(a => a.IdArtiste == artiste.IdArtiste);
if (stored == null)
{
this.logger.LogWarning("L'artiste {Id} n'a pas été trouvé pour l'update.", artiste.IdArtiste);
return;
}
stored.Nom = artiste.Nom;
stored.Biographie = artiste.Biographie;
stored.Titres = artiste.Titres;
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -4,7 +4,6 @@
namespace Webzine.Repository namespace Webzine.Repository
{ {
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -36,13 +35,13 @@ namespace Webzine.Repository
/// <inheritdoc/> /// <inheritdoc/>
public void Add(Commentaire commentaire) public void Add(Commentaire commentaire)
{ {
throw new NotSupportedException("Mode Local"); // TODO à implémenter this.dataStore.Commentaires.Add(commentaire);
} }
/// <inheritdoc/> /// <inheritdoc/>
public void Delete(Commentaire commentaire) public void Delete(Commentaire commentaire)
{ {
throw new NotSupportedException("Mode Local"); this.dataStore.Commentaires.Remove(commentaire);
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@@ -31,19 +31,19 @@ public class LocalStyleRepository : IStyleRepository
/// <inheritdoc/> /// <inheritdoc/>
public void Add(Style style) public void Add(Style style)
{ {
throw new NotSupportedException("Mode local"); this.dataStore.Styles.Add(style);
} }
/// <inheritdoc/> /// <inheritdoc/>
public void Delete(Style style) public void Delete(Style style)
{ {
throw new NotSupportedException("Mode local"); this.dataStore.Styles.Remove(style);
} }
/// <inheritdoc/> /// <inheritdoc/>
public Style Find(int id) public Style Find(int id)
{ {
return this.dataStore.Styles.Find(s => s.IdStyle == id); return this.dataStore.Styles.SingleOrDefault(s => s.IdStyle == id);
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -55,6 +55,14 @@ public class LocalStyleRepository : IStyleRepository
/// <inheritdoc/> /// <inheritdoc/>
public void Update(Style style) public void Update(Style style)
{ {
throw new NotSupportedException("Mode local"); var stored = this.dataStore.Styles.FirstOrDefault(s => s.IdStyle == style.IdStyle);
if (stored == null)
{
this.logger.LogWarning("Style with id {IdStyle} not found for update.", style.IdStyle);
return;
}
stored.Libelle = style.Libelle;
stored.Titres = style.Titres;
} }
} }

View File

@@ -28,7 +28,7 @@ public class LocalTitreRepository : ITitreRepository
/// <inheritdoc/> /// <inheritdoc/>
public void Add(Titre titre) public void Add(Titre titre)
{ {
throw new NotSupportedException("Mode local"); this.dataStore.Titres.Add(titre);
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -41,7 +41,7 @@ public class LocalTitreRepository : ITitreRepository
/// <inheritdoc/> /// <inheritdoc/>
public void Delete(Titre titre) public void Delete(Titre titre)
{ {
throw new NotSupportedException("Mode Local"); this.dataStore.Titres.Remove(titre);
} }
/// <inheritdoc/> /// <inheritdoc/>
@@ -115,6 +115,18 @@ public class LocalTitreRepository : ITitreRepository
/// <inheritdoc/> /// <inheritdoc/>
public void Update(Titre titre) public void Update(Titre titre)
{ {
throw new NotSupportedException("Mode local"); var stored = this.dataStore.Titres.FirstOrDefault(t => t.IdTitre == titre.IdTitre);
if (stored == null)
{
this.logger.LogWarning("Titre avec l'ID {Id} non trouvé pour mise à jour.", titre.IdTitre);
return;
}
stored.Libelle = titre.Libelle;
stored.DateCreation = titre.DateCreation;
stored.NbLectures = titre.NbLectures;
stored.NbLikes = titre.NbLikes;
stored.IdArtiste = titre.IdArtiste;
stored.Styles = titre.Styles;
} }
} }