feat(api): add owner-scoped documents metadata index

This commit is contained in:
cesnimda
2026-10-14 18:01:59 +02:00
parent 223dcf57d2
commit 8e4db121ae
18 changed files with 2792 additions and 6 deletions
@@ -0,0 +1,36 @@
using JobTrackerApi.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace JobTrackerApi.Controllers;
[ApiController]
[Route("api/documents")]
[Authorize(AuthenticationSchemes = "local")]
public sealed class DocumentsController(DocumentsIndexService documents, ICurrentUserService currentUser) : ControllerBase
{
[HttpGet]
public async Task<ActionResult<DocumentsPageDto>> List(
[FromQuery] int page = 1,
[FromQuery] int pageSize = 25,
[FromQuery] string? q = null,
[FromQuery] string type = "all",
[FromQuery] string state = "all",
[FromQuery] string visibility = "all",
[FromQuery] int? jobApplicationId = null,
[FromQuery] string sort = "date-desc",
CancellationToken cancellationToken = default)
{
var owner = currentUser.UserId;
if (owner is null) return Unauthorized();
if (page is < 1 or > 10000 || pageSize is < 1 or > 100 || q?.Length > 200 || jobApplicationId is <= 0)
return BadRequest("Invalid document pagination or search parameters.");
if (type is not ("all" or "cv" or "cover-letter" or "application-material" or "tailored-cv" or "attachment" or "submitted-package" or "email-draft")
|| state is not ("all" or "current" or "draft" or "frozen")
|| visibility is not ("all" or "private" or "public")
|| sort is not ("date-desc" or "date-asc" or "name-asc" or "name-desc"))
return BadRequest("Unsupported document filter or sort.");
return Ok(await documents.GetAsync(owner, page, pageSize, q, type, state, visibility, jobApplicationId, sort, cancellationToken));
}
}