summaryrefslogtreecommitdiffstats
path: root/api/WhatApi/Seed.cs
diff options
context:
space:
mode:
Diffstat (limited to 'api/WhatApi/Seed.cs')
-rw-r--r--api/WhatApi/Seed.cs44
1 files changed, 34 insertions, 10 deletions
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<Place>();
- var location = new Faker().Location();
- for (var i = 0; i < 1000; i++) {
+ public static void Full(Database db, Action<SeedOptions> 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