56 lines
2.2 KiB
C#
56 lines
2.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Mws.Application.Documents;
|
||
|
|
|
||
|
|
namespace Mws.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api")]
|
||
|
|
[Authorize]
|
||
|
|
public class DocumentsController(IDocumentService documentService) : ControllerBase
|
||
|
|
{
|
||
|
|
[HttpGet("documents/search")]
|
||
|
|
public async Task<ActionResult<List<DocumentNodeDto>>> Search([FromQuery] string? q, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await documentService.SearchAsync(User.GetUserId(), q ?? string.Empty, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("projects/{projectId:guid}/documents")]
|
||
|
|
public async Task<ActionResult<List<DocumentNodeDto>>> GetTree(Guid projectId, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await documentService.GetTreeAsync(User.GetUserId(), projectId, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("projects/{projectId:guid}/documents")]
|
||
|
|
public async Task<ActionResult<DocumentDto>> Create(Guid projectId, [FromBody] CreateDocumentRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var result = await documentService.CreateAsync(User.GetUserId(), projectId, request, ct);
|
||
|
|
return CreatedAtAction(nameof(Get), new { id = result.Id }, result);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("documents/{id:guid}")]
|
||
|
|
public async Task<ActionResult<DocumentDto>> Get(Guid id, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await documentService.GetAsync(User.GetUserId(), id, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPut("documents/{id:guid}")]
|
||
|
|
public async Task<ActionResult<DocumentDto>> Update(Guid id, [FromBody] UpdateDocumentRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await documentService.UpdateAsync(User.GetUserId(), id, request, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPut("documents/{id:guid}/move")]
|
||
|
|
public async Task<ActionResult<DocumentDto>> Move(Guid id, [FromBody] MoveDocumentRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
await documentService.MoveAsync(User.GetUserId(), id, request.NewParentId, ct);
|
||
|
|
return Ok(await documentService.GetAsync(User.GetUserId(), id, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpDelete("documents/{id:guid}")]
|
||
|
|
public async Task<IActionResult> Delete(Guid id, CancellationToken ct)
|
||
|
|
{
|
||
|
|
await documentService.DeleteAsync(User.GetUserId(), id, ct);
|
||
|
|
return NoContent();
|
||
|
|
}
|
||
|
|
}
|