PluralKit/PluralKit.API/Controllers/v1/AccountController.cs

34 lines
875 B
C#
Raw Normal View History

using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using PluralKit.Core;
namespace PluralKit.API
{
[ApiController]
[ApiVersion("1.0")]
2021-08-27 15:03:47 +00:00
[Route("v{version:apiVersion}/a")]
public class AccountController: ControllerBase
{
2020-08-29 11:46:27 +00:00
private readonly IDatabase _db;
private readonly ModelRepository _repo;
public AccountController(IDatabase db, ModelRepository repo)
{
2020-08-29 11:46:27 +00:00
_db = db;
_repo = repo;
}
[HttpGet("{aid}")]
public async Task<ActionResult<JObject>> GetSystemByAccount(ulong aid)
{
2020-08-29 11:46:27 +00:00
var system = await _db.Execute(c => _repo.GetSystemByAccount(c, aid));
if (system == null)
return NotFound("Account not found.");
2021-08-27 15:03:47 +00:00
return Ok(system.ToJson(User.ContextFor(system)));
}
}
}