summaryrefslogtreecommitdiff
path: root/Controllers/ApiTagController.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2026-05-06 22:33:52 +1000
committerJake Mannens <jake@asger.xyz>2026-05-06 22:33:52 +1000
commit2b66d00175950d845a794422433d4a350cf87775 (patch)
tree8b0a77d43d80faab235c14008206a926d4566859 /Controllers/ApiTagController.cs
parent60dd44153b5f2b233dc66032507ee6c9a925ed0e (diff)
v0.13av0.13a
Diffstat (limited to 'Controllers/ApiTagController.cs')
-rw-r--r--Controllers/ApiTagController.cs36
1 files changed, 36 insertions, 0 deletions
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<HBContext> dbFactory;
+
+ public ApiTagController(IDbContextFactory<HBContext> dbFactory) =>
+ this.dbFactory = dbFactory;
+
+ [HttpGet("definition")]
+ public async Task<IActionResult> 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<IActionResult> 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();
+ }
+}