refactor: optimiser la logique de génération de commentaires dans SeedDataLocal et les fichiers associés

This commit is contained in:
mirage
2026-03-27 15:07:40 +01:00
parent 30631676f8
commit 1eb8e93bfc
3 changed files with 17 additions and 11 deletions

View File

@@ -41,8 +41,7 @@ namespace Webzine.Entity.Fixtures
int count,
List<Artiste> artistes,
List<Style> styles,
List<string> albums,
List<Commentaire> commentaires
List<string> albums
)
{
Random random = new Random();
@@ -61,7 +60,7 @@ namespace Webzine.Entity.Fixtures
.RuleFor(t => t.NbLikes, f => f.Random.Int(0, 1000))
.RuleFor(t => t.Album, f => f.PickRandom(albums))
.RuleFor(t => t.Artiste, f => f.PickRandom(artistes))
.RuleFor(t => t.Commentaires, f => commentaires ?? new List<Commentaire>());
.RuleFor(t => t.Commentaires, f => new List<Commentaire>());
List<Titre> titres = faker.Generate(count);
foreach (Titre titre in titres)
@@ -133,11 +132,10 @@ namespace Webzine.Entity.Fixtures
/// <param name="min">Le nombre minimum de commentaires pouvant être créés. La valeur par défaut est 0.</params>
/// <param name="max">Le nombre maximun de commentaires pouvant être créés. La valeur par défaut est 5.</params>
/// <returns>Liste de commentaire.</returns>
public static List<Commentaire> GenererListeCommentaire(Titre titre, int min = 0, int max = 5)
public static List<Commentaire> GenererListeCommentaire(Titre titre, int min = 0, int max = 5, int idStart = 1)
{
Random random = new Random();
int count = random.Next(min, max + 1);
int idStart = 1;
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
.RuleFor(a => a.IdCommentaire, f => f.IndexFaker + idStart)