blob: 26e3dc436ffd1b72daa8b4ff7ba405c01cda4fd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace HyperBooru.Controllers;
[ApiController]
[Authorize]
[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();
}
}
|