diff --git a/BantFlags/Controllers/FlagsController.cs b/BantFlags/Controllers/FlagsController.cs index 00af538..cd078f8 100644 --- a/BantFlags/Controllers/FlagsController.cs +++ b/BantFlags/Controllers/FlagsController.cs @@ -57,7 +57,7 @@ namespace BantFlags.Controllers { string splitFlag = (version ?? 0) > 1 ? "," : "||"; // comma for v2+, else || for backwards compatibility. - Result post = PostModel.Create(post_nr, board, regions, splitFlag, Database.KnownFlags); + Result post = PostModel.Create(post_nr, board, regions, splitFlag, Database.KnownFlags, Database.Boards); if (post.Failed) { @@ -66,7 +66,7 @@ namespace BantFlags.Controllers await Database.InsertPost(post.Value); - return Ok(post); + return Ok(post.Value); } /// diff --git a/BantFlags/Data/Database/DatabaseService.cs b/BantFlags/Data/Database/DatabaseService.cs index be886a5..89afbb3 100644 --- a/BantFlags/Data/Database/DatabaseService.cs +++ b/BantFlags/Data/Database/DatabaseService.cs @@ -16,10 +16,14 @@ namespace BantFlags.Data.Database public HashSet KnownFlags { get; private set; } + public HashSet Boards { get; private set; } + public DatabaseService(DatabaseServiceConfig dbConfig) { ConnectionPool = new MySqlConnectionPool(dbConfig.ConnectionString, dbConfig.PoolSize); + Boards = dbConfig.Boards; + UpdateKnownFlags().Wait(); // It's okay to deadlock here since it's only initialised at startup. } @@ -101,5 +105,7 @@ namespace BantFlags.Data.Database public string ConnectionString { get; set; } public int PoolSize { get; set; } + + public HashSet Boards { get; set; } } } \ No newline at end of file diff --git a/BantFlags/Data/PostModel.cs b/BantFlags/Data/PostModel.cs index 45764ed..7f719e7 100644 --- a/BantFlags/Data/PostModel.cs +++ b/BantFlags/Data/PostModel.cs @@ -19,10 +19,9 @@ namespace BantFlags.Data Flags = flags; } - public static Result Create(string post_nr, string board, string regions, string splitFlag, HashSet knownFlags) + public static Result Create(string post_nr, string board, string regions, string splitFlag, HashSet knownFlags, HashSet boards) { string[] empty = { "empty, or there were errors. Re-set your flags." }; - string[] boards = { "bant", "nap", "srsbsn" }; // TODO: Move this to appsettings and make a singleton for it. if (!int.TryParse(post_nr, out int postNumber)) return Result.Fail("Invalid post number.");