From 2b66d00175950d845a794422433d4a350cf87775 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Wed, 6 May 2026 22:33:52 +1000 Subject: v0.13a --- Controllers/ApiTagController.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Controllers/ApiTagController.cs (limited to 'Controllers/ApiTagController.cs') diff --git a/Controllers/ApiTagController.cs b/Controllers/ApiTagController.cs new file mode 100644 index 0000000..afd5b05 --- /dev/null +++ b/Controllers/ApiTagController.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace HyperBooru.Controllers; + +[ApiController] +[Route("/api/tag")] +public class ApiTagController : Controller { + private IDbContextFactory dbFactory; + + public ApiTagController(IDbContextFactory dbFactory) => + this.dbFactory = dbFactory; + + [HttpGet("definition")] + public async Task GetAllTagDefinitionsAsync() { + using var db = dbFactory.CreateDbContext(); + + var definitions = await db.TagDefinitions + .Include(td => td.ImplicitTags) + .Select(td => (ApiModels.TagDefinition)td) + .ToArrayAsync(); + + return Ok(definitions); + } + + [HttpGet("definition/{tagDefinitionId}")] + public async Task GetTagDefinitionAsync([FromRoute] Guid tagDefinitionId) { + using var db = dbFactory.CreateDbContext(); + + var tagDefinition = await db.TagDefinitions + .Include(td => td.ImplicitTags) + .FirstOrDefaultAsync(td => td.Guid == tagDefinitionId); + + return tagDefinition is not null ? Ok(tagDefinition) : NotFound(); + } +} -- cgit v1.3