Move valid boards to appsettings.

dotnetflags
C-xC-c 5 years ago
parent f38f0125d7
commit 122009c4c5

@ -57,7 +57,7 @@ namespace BantFlags.Controllers
{
string splitFlag = (version ?? 0) > 1 ? "," : "||"; // comma for v2+, else || for backwards compatibility.
Result<PostModel> post = PostModel.Create(post_nr, board, regions, splitFlag, Database.KnownFlags);
Result<PostModel> 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);
}
/// <summary>

@ -16,10 +16,14 @@ namespace BantFlags.Data.Database
public HashSet<string> KnownFlags { get; private set; }
public HashSet<string> 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<string> Boards { get; set; }
}
}

@ -19,10 +19,9 @@ namespace BantFlags.Data
Flags = flags;
}
public static Result<PostModel> Create(string post_nr, string board, string regions, string splitFlag, HashSet<string> knownFlags)
public static Result<PostModel> Create(string post_nr, string board, string regions, string splitFlag, HashSet<string> knownFlags, HashSet<string> 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<PostModel>.Fail("Invalid post number.");

Loading…
Cancel
Save