Skip to content

Commit

Permalink
Merge pull request #4 from moevm/db_test_data_load
Browse files Browse the repository at this point in the history
db_test_data_load
  • Loading branch information
homin12 authored Nov 7, 2024
2 parents b6b0cf1 + adad81b commit 17e1b79
Show file tree
Hide file tree
Showing 4 changed files with 982 additions and 2 deletions.
26 changes: 24 additions & 2 deletions backend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddSingleton(new MongoClient("mongodb://username:password@database:27017"));
var client = new MongoClient("mongodb://username:password@database:27017");
builder.Services.AddSingleton(client);

var app = builder.Build();

Expand All @@ -21,4 +21,26 @@

app.UseHttpsRedirection();

var db = client.GetDatabase("animedb");
var collection = db.GetCollection<BsonDocument>("user");
if(await collection.CountDocumentsAsync("{}") == 0){
string text = System.IO.File.ReadAllText("./test_data/anime_db_user.json");
var document = BsonSerializer.Deserialize<List<BsonDocument>>(text);
await collection.InsertManyAsync(document);
}

collection = db.GetCollection<BsonDocument>("anime");
if(await collection.CountDocumentsAsync("{}") == 0){
string text = System.IO.File.ReadAllText("./test_data/anime_db_anime.json");
var document = BsonSerializer.Deserialize<List<BsonDocument>>(text);
await collection.InsertManyAsync(document);
}

collection = db.GetCollection<BsonDocument>("review");
if(await collection.CountDocumentsAsync("{}") == 0){
string text = System.IO.File.ReadAllText("./test_data/anime_db_review.json");
var document = BsonSerializer.Deserialize<List<BsonDocument>>(text);
await collection.InsertManyAsync(document);
}

app.Run();
Loading

0 comments on commit 17e1b79

Please sign in to comment.