From 68ffad06a6cfd2cd2015ab03fb82bf69629dd7ec Mon Sep 17 00:00:00 2001 From: ivar Date: Tue, 2 Dec 2025 22:38:23 +0100 Subject: Move off razor pages --- api/WhatApi/Seed.cs | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'api/WhatApi/Seed.cs') diff --git a/api/WhatApi/Seed.cs b/api/WhatApi/Seed.cs index 13bd4aa..0e8ab59 100644 --- a/api/WhatApi/Seed.cs +++ b/api/WhatApi/Seed.cs @@ -4,20 +4,44 @@ using WhatApi.Tables; namespace WhatApi; -public partial class Program +public static class Seed { - private static void Seed(Database db) { - if (db.Places.Any() || true) return; - var places = new List(); - var location = new Faker().Location(); - for (var i = 0; i < 1000; i++) { + public static void Full(Database db, Action seedOptions) { + var opt = new SeedOptions(); + seedOptions.Invoke(opt); + Content(db, opt); + } + + public static void Content(Database db, SeedOptions opt) { + var any = db.Places.Any(); + if (any) { + if (!opt.ClearTables) return; + db.Places.RemoveRange(db.Places.ToList()); + db.SaveChanges(); + } + var faker = new Faker(); + for (var i = 0; i < 30; i++) { + var ip = faker.Internet.IpAddress(); + var content = new Content() { + Id = Guid.NewGuid(), + Ip = ip, + Mime = "image/jpeg", + BlobId = new Guid("3ae0ea2d-851d-4e27-ad89-205822126395") + }; + var location = faker.Location(); var point = location.AreaCircle(59.91838, 10.73861, 30000); - places.Add(new Place() { + var place = new Place() { Location = new Point(new Coordinate(point.Longitude, point.Latitude)), - ContentId = new Guid("1337710a-8cdb-4d50-815f-772c0e9f1482") - }); + Content = content + }; + db.Places.Add(place); } - db.Places.AddRange(places); + db.SaveChanges(); } +} + +public class SeedOptions +{ + public bool ClearTables { get; set; } } \ No newline at end of file -- cgit v1.3