added rate limiting middleware and configured it. added quotes data in json format. added method to seeder to seed database with quote data.

This commit is contained in:
StevanFreeborn
2022-06-21 23:24:56 -05:00
parent b452e8db0b
commit 9b6365b88b
8 changed files with 4207 additions and 17 deletions
+23 -4
View File
@@ -11,6 +11,7 @@ namespace server.Persistence.Seed
private readonly IConfiguration _config;
private readonly IMongoCollection<Season> _seasons;
private readonly IMongoCollection<Episode> _episodes;
private readonly IMongoCollection<Quote> _quotes;
public Seeder()
{
@@ -22,15 +23,16 @@ namespace server.Persistence.Seed
_database = _client.GetDatabase(_config.GetSection("MongoDBSettings:DatabaseName").Value);
_seasons = _database.GetCollection<Season>(_config.GetSection("MongoDBSettings:SeasonsCollection").Value);
_episodes = _database.GetCollection<Episode>(_config.GetSection("MongoDBSettings:EpisodesCollection").Value);
_quotes = _database.GetCollection<Quote>(_config.GetSection("MongoDBSettings:QuotesCollection").Value);
}
public async Task SeedSeasonsAsync()
{
await _seasons.DeleteManyAsync(season => true);
var fileName = "seasons.json";
const string fileName = "seasons.json";
var seasonsFilePath = Path.Combine(AppContext.BaseDirectory, $"Persistence/Seed/Data/{fileName}");
var seasonsJson = File.ReadAllText(seasonsFilePath);
var seasonsJson = await File.ReadAllTextAsync(seasonsFilePath);
var seasons = JsonSerializer.Deserialize<List<Season>>(seasonsJson);
if(seasons != null)
@@ -44,9 +46,9 @@ namespace server.Persistence.Seed
{
await _episodes.DeleteManyAsync(episode => true);
var fileName = "episodes.json";
const string fileName = "episodes.json";
var episodesFilePath = Path.Combine(AppContext.BaseDirectory, $"Persistence/Seed/Data/{fileName}");
var episodesJson = File.ReadAllText(episodesFilePath);
var episodesJson = await File.ReadAllTextAsync(episodesFilePath);
var episodes = JsonSerializer.Deserialize<List<Episode>>(episodesJson);
if (episodes != null)
@@ -55,5 +57,22 @@ namespace server.Persistence.Seed
Console.WriteLine($"Seeded databases with episodes from {fileName}");
}
}
public async Task SeedQuotesAsync()
{
await _quotes.DeleteManyAsync(quotes => true);
const string fileName = "quotes.json";
var quotesFilePath = Path.Combine(AppContext.BaseDirectory, $"Persistence/Seed/Data/{fileName}");
var quotesJson = await File.ReadAllTextAsync(quotesFilePath);
var quotes = JsonSerializer.Deserialize<List<Episode>>(quotesJson);
if (quotes != null)
{
await _episodes.InsertManyAsync(quotes);
Console.WriteLine($"Seeded databases with quotes from {fileName}");
}
}
}
}