🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using ColaFlow.Modules.ProjectManagement.Application.DTOs;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Commands.CreateProject;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetProjectById;
|
|
using ColaFlow.Modules.ProjectManagement.Application.Queries.GetProjects;
|
|
|
|
namespace ColaFlow.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Projects API Controller
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/v1/[controller]")]
|
|
public class ProjectsController : ControllerBase
|
|
{
|
|
private readonly IMediator _mediator;
|
|
|
|
public ProjectsController(IMediator mediator)
|
|
{
|
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all projects
|
|
/// </summary>
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(List<ProjectDto>), StatusCodes.Status200OK)]
|
|
public async Task<IActionResult> GetProjects(CancellationToken cancellationToken = default)
|
|
{
|
|
var query = new GetProjectsQuery();
|
|
var result = await _mediator.Send(query, cancellationToken);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get project by ID
|
|
/// </summary>
|
|
[HttpGet("{id:guid}")]
|
|
[ProducesResponseType(typeof(ProjectDto), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
public async Task<IActionResult> GetProject(Guid id, CancellationToken cancellationToken = default)
|
|
{
|
|
var query = new GetProjectByIdQuery(id);
|
|
var result = await _mediator.Send(query, cancellationToken);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a new project
|
|
/// </summary>
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(ProjectDto), StatusCodes.Status201Created)]
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
public async Task<IActionResult> CreateProject(
|
|
[FromBody] CreateProjectCommand command,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var result = await _mediator.Send(command, cancellationToken);
|
|
return CreatedAtAction(nameof(GetProject), new { id = result.Id }, result);
|
|
}
|
|
}
|