55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Mws.Application.Projects;
|
||
|
|
|
||
|
|
namespace Mws.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/projects")]
|
||
|
|
[Authorize]
|
||
|
|
public class ProjectsController(IProjectService projectService) : ControllerBase
|
||
|
|
{
|
||
|
|
[HttpGet]
|
||
|
|
public async Task<ActionResult<List<ProjectDto>>> GetAll(CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await projectService.GetProjectsAsync(User.GetUserId(), ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("search")]
|
||
|
|
public async Task<ActionResult<List<ProjectDto>>> Search([FromQuery] string? q, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await projectService.SearchAsync(User.GetUserId(), q ?? string.Empty, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("{projectId:guid}")]
|
||
|
|
public async Task<ActionResult<ProjectDto>> Get(Guid projectId, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await projectService.GetProjectAsync(User.GetUserId(), projectId, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("{projectId:guid}/overview")]
|
||
|
|
public async Task<ActionResult<ProjectOverviewDto>> Overview(Guid projectId, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await projectService.GetOverviewAsync(User.GetUserId(), projectId, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost]
|
||
|
|
public async Task<ActionResult<ProjectDto>> Create([FromBody] CreateProjectRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
var result = await projectService.CreateProjectAsync(User.GetUserId(), request, ct);
|
||
|
|
return CreatedAtAction(nameof(Get), new { projectId = result.Id }, result);
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPut("{projectId:guid}")]
|
||
|
|
public async Task<ActionResult<ProjectDto>> Update(Guid projectId, [FromBody] UpdateProjectRequest request, CancellationToken ct)
|
||
|
|
{
|
||
|
|
return Ok(await projectService.UpdateProjectAsync(User.GetUserId(), projectId, request, ct));
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpDelete("{projectId:guid}")]
|
||
|
|
public async Task<IActionResult> Delete(Guid projectId, CancellationToken ct)
|
||
|
|
{
|
||
|
|
await projectService.ArchiveProjectAsync(User.GetUserId(), projectId, ct);
|
||
|
|
return NoContent();
|
||
|
|
}
|
||
|
|
}
|