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;
|
2026-08-19 23:25:08 +07:00
|
|
|
using mws.backend.dotnet.application.Common;
|
|
|
|
|
using mws.backend.dotnet.application.Projects;
|
2026-09-13 18:02:09 +07:00
|
|
|
using mws.backend.dotnet.domain.Projects;
|
2026-08-13 23:10:22 +07:00
|
|
|
|
2026-08-19 23:25:08 +07:00
|
|
|
namespace mws.backend.dotnet.api.Controllers;
|
2026-08-13 23:10:22 +07:00
|
|
|
|
|
|
|
|
[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]
|
2026-09-13 18:02:09 +07:00
|
|
|
public async Task<ActionResult<PagedResult<ProjectDto>>> GetAll(
|
|
|
|
|
[FromQuery] string? q, [FromQuery] ProjectStatus? status,
|
|
|
|
|
[FromQuery] string? createdBy, [FromQuery] string? updatedBy,
|
|
|
|
|
[FromQuery] int page = 1, [FromQuery] int pageSize = 20, CancellationToken ct = default)
|
2026-08-13 23:10:22 +07:00
|
|
|
{
|
2026-09-13 18:02:09 +07:00
|
|
|
var filter = new ProjectListFilter(User.GetUserId(), q, status, createdBy, updatedBy);
|
|
|
|
|
return Ok(await sender.Send(new GetProjectsQuery(filter, page, pageSize), 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
|
|
|
}
|