2019-07-17 11:45:36 +00:00
|
|
|
using System.Threading.Tasks;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-07-17 11:45:36 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
2019-12-28 14:52:59 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
|
|
|
namespace PluralKit.API
|
2019-07-17 11:45:36 +00:00
|
|
|
{
|
|
|
|
[ApiController]
|
2020-05-07 02:39:49 +00:00
|
|
|
[ApiVersion("1.0")]
|
|
|
|
[Route( "v{version:apiVersion}/a" )]
|
2019-07-17 11:45:36 +00:00
|
|
|
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)
|
2019-07-17 11:45:36 +00:00
|
|
|
{
|
2020-08-29 11:46:27 +00:00
|
|
|
_db = db;
|
|
|
|
_repo = repo;
|
2019-07-17 11:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[HttpGet("{aid}")]
|
2019-12-28 14:52:59 +00:00
|
|
|
public async Task<ActionResult<JObject>> GetSystemByAccount(ulong aid)
|
2019-07-17 11:45:36 +00:00
|
|
|
{
|
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.");
|
2019-07-17 11:45:36 +00:00
|
|
|
|
2020-06-15 23:15:59 +00:00
|
|
|
return Ok(system.ToJson(User.ContextFor(system)));
|
2019-07-17 11:45:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|