- Added `BackToPerMethodId` constant and updated validation rules in `CloseWorkflowCommandValidator`. - Refactored `GetWorkflowsQueryHandler` for simpler `hasListingData` logic. - Replaced strongly-typed properties with `JsonElement` in `ContractsSourceBlock` and `FerdinandSourceBlock`. - Updated `WorkflowListingReadModel` to use smaller data types for efficiency. - Refactored `WorkflowRepository` to use JSON-based data retrieval and parsing. - Introduced `MetaOnlyResponse` and `WorkflowsResponse` for consistent API responses. - Updated `DocumentsController` and `WorkflowsController` to use new response types. - Added `ApiKeyAuthMiddleware` for API key validation and integrated it into the middleware pipeline. - Refactored `ExceptionHandlingMiddleware` to use `MetaOnlyResponse` for error handling. - Performed general cleanup and modernization for improved readability and maintainability.
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using DigitalData.TaskFlow.API.Contracts.Workflows;
|
|
using DigitalData.TaskFlow.API.Contracts.Common;
|
|
using DigitalData.TaskFlow.Application.Features.Workflows.Commands.CloseWorkflow;
|
|
using DigitalData.TaskFlow.Application.Features.Workflows.Queries.GetWorkflows;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace DigitalData.TaskFlow.API.Controllers;
|
|
|
|
/// <summary>
|
|
/// Provides workflow read and close endpoints.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/workflows")]
|
|
public sealed class WorkflowsController(ISender sender) : ControllerBase
|
|
{
|
|
/// <summary>
|
|
/// Returns open workflows for a WISAG user identifier.
|
|
/// </summary>
|
|
/// <param name="wisagId">WISAG user identifier.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Workflow response envelope grouped by source.</returns>
|
|
[HttpGet("{wisagId:int}")]
|
|
[ProducesResponseType(typeof(WorkflowsResponse), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<WorkflowsResponse>> GetAsync(
|
|
[FromRoute] int wisagId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var response = await sender.Send(new GetWorkflowsQuery(wisagId), cancellationToken);
|
|
|
|
var sources = response.Data?.Sources
|
|
.Cast<object>()
|
|
.ToList()
|
|
?? [];
|
|
|
|
return Ok(new WorkflowsResponse
|
|
{
|
|
Meta = response.Meta,
|
|
Sources = sources
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies a closing decision to a workflow process.
|
|
/// </summary>
|
|
/// <param name="wisagId">WISAG user identifier.</param>
|
|
/// <param name="source">Source system name.</param>
|
|
/// <param name="processId">Process identifier.</param>
|
|
/// <param name="request">Closing request payload.</param>
|
|
/// <param name="cancellationToken">Cancellation token.</param>
|
|
/// <returns>Close result envelope.</returns>
|
|
[HttpPost("{wisagId:int}/{source}/{processId:int}/closing")]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status200OK)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status400BadRequest)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status401Unauthorized)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status403Forbidden)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status404NotFound)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status409Conflict)]
|
|
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status500InternalServerError)]
|
|
public async Task<ActionResult<MetaOnlyResponse>> 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(new MetaOnlyResponse
|
|
{
|
|
Meta = response.Meta
|
|
});
|
|
}
|
|
}
|