44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
|
using ActivityPub.Utils;
|
|||
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
|||
|
namespace ActivityPub.Controllers;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// API endpoint(s) for retrieving objects
|
|||
|
/// </summary>
|
|||
|
[Route("")]
|
|||
|
[ApiController]
|
|||
|
public class ObjectController : ControllerBase
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// TODO: Temporary Object data store (until I work out the data layer)
|
|||
|
/// </summary>
|
|||
|
public static Dictionary<string, Dictionary<string, Object>> _objects = new();
|
|||
|
private readonly ILogger<ObjectController> _logger;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Default constructor
|
|||
|
/// </summary>
|
|||
|
/// <param name="logger">The logger</param>
|
|||
|
public ObjectController(ILogger<ObjectController> logger)
|
|||
|
{
|
|||
|
_logger = logger;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets a single object by id
|
|||
|
/// </summary>
|
|||
|
/// <param name="type">The type of Object to retrieve (see https://www.w3.org/TR/activitystreams-vocabulary/#object-types) </param>
|
|||
|
/// <param name="id">The identifier of the object</param>
|
|||
|
/// <returns>The requested object, or else 404</returns>
|
|||
|
[HttpGet("{type}/{id}", Name = "GetObject")]
|
|||
|
public IActionResult Get(string type, string id)
|
|||
|
{
|
|||
|
string properType = Types.Normalize(type);
|
|||
|
if (Types.IsObjectOrLink(properType) && _objects.ContainsKey(properType) && _objects[properType].ContainsKey(id.ToLower()))
|
|||
|
return this.Ok(_objects[properType][id.ToLower()]);
|
|||
|
|
|||
|
return NotFound();
|
|||
|
}
|
|||
|
}
|