Skip to content

Commit

Permalink
supports create global config
Browse files Browse the repository at this point in the history
  • Loading branch information
sdcb committed Dec 9, 2024
1 parent a81e4f7 commit fade5d8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/BE/Controllers/Admin/GlobalConfigs/GlobalConfigController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,31 @@ public async Task<ActionResult> UpdateGlobalConfig([FromBody] GlobalConfigDto re
}
return NoContent();
}

[HttpPost]
public async Task<ActionResult> 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();
}
}

0 comments on commit fade5d8

Please sign in to comment.