diff --git a/src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs b/src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs index a2c06d23..453eb99f 100644 --- a/src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs +++ b/src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs @@ -52,4 +52,31 @@ public async Task UpdateGlobalConfig([FromBody] GlobalConfigDto re } return NoContent(); } + + [HttpPost] + public async Task CreateGlobalConfig([FromBody] GlobalConfigDto req, CancellationToken cancellationToken) + { + Config? config = await db.Configs.FindAsync([req.Key], cancellationToken); + if (config != null) + { + return this.BadRequestMessage("Key already exists"); + } + // ensure value is valid json + try + { + JsonDocument.Parse(req.Value); + } + catch (JsonException) + { + return this.BadRequestMessage("Invalid JSON"); + } + await db.Configs.AddAsync(new Config() + { + Key = req.Key, + Value = req.Value, + Description = req.Description, + }, cancellationToken); + await db.SaveChangesAsync(cancellationToken); + return NoContent(); + } }