2021-09-30 02:30:20 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
namespace PluralKit.API
|
|
|
|
{
|
|
|
|
[ApiController]
|
|
|
|
[ApiVersion("2.0")]
|
|
|
|
[Route("v{version:apiVersion}/systems")]
|
|
|
|
public class SystemControllerV2: PKControllerBase
|
|
|
|
{
|
|
|
|
public SystemControllerV2(IServiceProvider svc) : base(svc) { }
|
|
|
|
|
2021-10-02 01:50:01 +00:00
|
|
|
[HttpGet("{systemRef}")]
|
|
|
|
public async Task<IActionResult> SystemGet(string systemRef)
|
2021-09-30 02:30:20 +00:00
|
|
|
{
|
2021-10-02 01:50:01 +00:00
|
|
|
var system = await ResolveSystem(systemRef);
|
|
|
|
if (system == null) return NotFound();
|
2021-10-12 09:17:54 +00:00
|
|
|
else return Ok(system.ToJson(this.ContextFor(system), v: APIVersion.V2));
|
2021-09-30 02:30:20 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 13:35:20 +00:00
|
|
|
[HttpPatch]
|
|
|
|
public async Task<IActionResult> DoSystemPatch([FromBody] JObject data)
|
2021-09-30 02:30:20 +00:00
|
|
|
{
|
2021-10-14 13:35:20 +00:00
|
|
|
var system = await ResolveSystem("@me");
|
|
|
|
var patch = SystemPatch.FromJSON(data, APIVersion.V2);
|
|
|
|
|
|
|
|
patch.AssertIsValid();
|
|
|
|
if (patch.Errors.Count > 0)
|
|
|
|
throw new ModelParseError(patch.Errors);
|
|
|
|
|
|
|
|
var newSystem = await _repo.UpdateSystem(system.Id, patch);
|
|
|
|
return Ok(newSystem.ToJson(LookupContext.ByOwner, v: APIVersion.V2));
|
2021-09-30 02:30:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|