AP.NET/Controllers/ObjectController.cs
Gordon Pedersen 7c84fbc4c5 Initial commit way too late
There's a lot of rubbish in here, but I don't want to lose anything, so I'm going to commit it all before getting rid of some of the trash.
2024-04-05 15:26:57 +11:00

43 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();
}
}