Merge pull request 'refactor: optimiser la logique de génération de commentaires dans SeedDataLocal et les fichiers associés' (#135) from j2/fix/dev into dev
Reviewed-on: https://10.4.0.131/gitea/DI1-P4-E1/Webzine/pulls/135 Reviewed-by: Loic Masi <loic.masi@diiage.org>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -46,11 +46,17 @@ namespace Webzine.Repository
|
||||
this.context.SaveChanges();
|
||||
|
||||
List<string> albums = SeedDataLocal.GenererListeAlbums(3);
|
||||
List<Commentaire> commentaires = new List<Commentaire>();
|
||||
List<Titre> titres = SeedDataLocal.GenererListeTitre(nbTitres, artistes, styles, albums, commentaires);
|
||||
this.context.Titres.AddRange(titres);
|
||||
this.context.SaveChanges();
|
||||
List<Titre> titres = SeedDataLocal.GenererListeTitre(nbTitres, artistes, styles, albums);
|
||||
|
||||
int commentaireIdStart = 1;
|
||||
foreach (var titre in titres)
|
||||
{
|
||||
var commentairesDuTitre = SeedDataLocal.GenererListeCommentaire(titre, 0, 5, commentaireIdStart);
|
||||
titre.Commentaires.AddRange(commentairesDuTitre);
|
||||
commentaireIdStart += commentairesDuTitre.Count;
|
||||
}
|
||||
|
||||
this.context.Titres.AddRange(titres);
|
||||
this.context.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,11 +99,13 @@ try
|
||||
var styles = SeedDataLocal.GenererListeStyle(15, 20);
|
||||
var albums = SeedDataLocal.GenererListeAlbums(50);
|
||||
var commentaires = new List<Commentaire>();
|
||||
var titres = SeedDataLocal.GenererListeTitre(500, artistes, styles, albums, commentaires);
|
||||
var titres = SeedDataLocal.GenererListeTitre(500, artistes, styles, albums);
|
||||
|
||||
foreach (var titre in titres)
|
||||
{
|
||||
commentaires.AddRange(SeedDataLocal.GenererListeCommentaire(titre, 0, 5));
|
||||
var commentairesForTitre = SeedDataLocal.GenererListeCommentaire(titre, 0, 5);
|
||||
titre.Commentaires.AddRange(commentairesForTitre);
|
||||
commentaires.AddRange(commentairesForTitre);
|
||||
}
|
||||
|
||||
store.Artistes.AddRange(artistes);
|
||||
|
||||
Reference in New Issue
Block a user