using DigitalData.TaskFlow.API.Contracts.Workflows; using DigitalData.TaskFlow.Application.Features.Workflows.Commands.CloseWorkflow; using DigitalData.TaskFlow.Application.Features.Workflows.Queries.GetWorkflows; using DigitalData.TaskFlow.Domain.Closing; using DigitalData.TaskFlow.Domain.Common; using DigitalData.TaskFlow.Domain.Workflows; using MediatR; using Microsoft.AspNetCore.Mvc; namespace DigitalData.TaskFlow.API.Controllers; /// /// Provides workflow read and close endpoints. /// [ApiController] [Route("api/workflows")] public sealed class WorkflowsController(ISender sender) : ControllerBase { /// /// Returns open workflows for a WISAG user identifier. /// /// WISAG user identifier. /// Cancellation token. /// Workflow response envelope grouped by source. [HttpGet("{wisagId:int}")] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status500InternalServerError)] public async Task>> GetAsync( [FromRoute] int wisagId, CancellationToken cancellationToken) { var response = await sender.Send(new GetWorkflowsQuery(wisagId), cancellationToken); return Ok(response); } /// /// Applies a closing decision to a workflow process. /// /// WISAG user identifier. /// Source system name. /// Process identifier. /// Closing request payload. /// Cancellation token. /// Close result envelope. [HttpPost("{wisagId:int}/{source}/{processId:int}/closing")] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ApiEnvelope), StatusCodes.Status500InternalServerError)] public async Task>> CloseAsync( [FromRoute] int wisagId, [FromRoute] string source, [FromRoute] int processId, [FromBody] CloseWorkflowRequest request, CancellationToken cancellationToken) { var command = new CloseWorkflowCommand( wisagId, source, processId, request.ClosingMethodId, request.Comment, request.RejectionReasonId); var response = await sender.Send(command, cancellationToken); return Ok(response); } }