refactor(api): update document endpoints and middleware contracts

This commit is contained in:
2026-10-31 17:09:33 +01:00
parent 9b60f5116b
commit 893b063ae9
13 changed files with 146 additions and 321 deletions

View File

@@ -1,9 +1,7 @@
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 DigitalData.TaskFlow.Application.Features.Workflows.Queries;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
namespace DigitalData.TaskFlow.API.Controllers;
@@ -21,64 +19,12 @@ public sealed class WorkflowsController(ISender sender) : ControllerBase
/// <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)
[ProducesResponseType(typeof(JsonElement), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status502BadGateway)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult<JsonElement>> 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
});
return Ok(await sender.Send(new GetWorkflowsQuery(wisagId), cancellationToken));
}
}