2019-07-17 12:05:44 +00:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2020-02-12 14:16:19 +00:00
|
|
|
|
2019-12-28 14:52:59 +00:00
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
2020-02-12 14:16:19 +00:00
|
|
|
using PluralKit.Core;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.API;
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
[Route("v{version:apiVersion}/msg")]
|
|
|
|
public class MessageController: ControllerBase
|
2019-07-17 12:05:44 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly IDatabase _db;
|
|
|
|
private readonly ModelRepository _repo;
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public MessageController(ModelRepository repo, IDatabase db)
|
|
|
|
{
|
|
|
|
_repo = repo;
|
|
|
|
_db = db;
|
|
|
|
}
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
[HttpGet("{mid}")]
|
|
|
|
public async Task<ActionResult<JObject>> GetMessage(ulong mid)
|
|
|
|
{
|
|
|
|
var msg = await _db.Execute(c => _repo.GetMessage(c, mid));
|
|
|
|
if (msg == null) return NotFound("Message not found.");
|
2019-07-17 12:05:44 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
return msg.ToJson(User.ContextFor(msg.System), APIVersion.V1);
|
2019-07-17 12:05:44 +00:00
|
|
|
}
|
|
|
|
}
|