mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-05 05:17:54 +00:00
API patch improvements
- add PatchObject.CheckIsValid - use transaction when creating member, as to not create a member if the patch is invalid - return edited system in `PATCH /s` endpoint
This commit is contained in:
parent
a2d2036851
commit
b34ed5c4c0
10 changed files with 103 additions and 22 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -140,13 +141,18 @@ namespace PluralKit.API
|
|||
try
|
||||
{
|
||||
patch = JsonModelExt.ToSystemPatch(changes);
|
||||
patch.CheckIsValid();
|
||||
}
|
||||
catch (JsonModelParseError e)
|
||||
{
|
||||
return BadRequest(e.Message);
|
||||
}
|
||||
catch (InvalidPatchException e)
|
||||
{
|
||||
return BadRequest($"Request field '{e.Message}' is invalid.");
|
||||
}
|
||||
|
||||
await _repo.UpdateSystem(conn, system!.Id, patch);
|
||||
system = await _repo.UpdateSystem(conn, system!.Id, patch);
|
||||
return Ok(system.ToJson(User.ContextFor(system)));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue