2026-08-14 08:46:06 +07:00
|
|
|
using MediatR;
|
2026-08-13 23:10:22 +07:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Mws.Application.Projects;
|
|
|
|
|
|
|
|
|
|
namespace Mws.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/projects")]
|
|
|
|
|
[Authorize]
|
2026-08-14 08:46:06 +07:00
|
|
|
public class ProjectsController(ISender sender) : ControllerBase
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<List<ProjectDto>>> GetAll(CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
return Ok(await sender.Send(new GetProjectsQuery(User.GetUserId()), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("search")]
|
|
|
|
|
public async Task<ActionResult<List<ProjectDto>>> Search([FromQuery] string? q, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
return Ok(await sender.Send(new SearchProjectsQuery(User.GetUserId(), q ?? string.Empty), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{projectId:guid}")]
|
|
|
|
|
public async Task<ActionResult<ProjectDto>> Get(Guid projectId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
return Ok(await sender.Send(new GetProjectQuery(User.GetUserId(), projectId), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("{projectId:guid}/overview")]
|
|
|
|
|
public async Task<ActionResult<ProjectOverviewDto>> Overview(Guid projectId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
return Ok(await sender.Send(new GetProjectOverviewQuery(User.GetUserId(), projectId), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<ActionResult<ProjectDto>> Create([FromBody] CreateProjectRequest request, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
var result = await sender.Send(new CreateProjectCommand(User.GetUserId(), request), ct);
|
2026-08-13 23:10:22 +07:00
|
|
|
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)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
return Ok(await sender.Send(new UpdateProjectCommand(User.GetUserId(), projectId, request), ct));
|
2026-08-13 23:10:22 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{projectId:guid}")]
|
|
|
|
|
public async Task<IActionResult> Delete(Guid projectId, CancellationToken ct)
|
|
|
|
|
{
|
2026-08-14 08:46:06 +07:00
|
|
|
await sender.Send(new ArchiveProjectCommand(User.GetUserId(), projectId), ct);
|
2026-08-13 23:10:22 +07:00
|
|
|
return NoContent();
|
|
|
|
|
}
|
2026-08-14 08:46:06 +07:00
|
|
|
}
|