Refactor workflows and improve API responses
- 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.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using DigitalData.TaskFlow.Application.Features.Documents.Queries.GetDocument;
|
||||
using DigitalData.TaskFlow.API.Contracts.Common;
|
||||
using DigitalData.TaskFlow.Domain.Common;
|
||||
using DigitalData.TaskFlow.Domain.Documents;
|
||||
using MediatR;
|
||||
@@ -21,9 +22,11 @@ public sealed class DocumentsController(ISender sender) : ControllerBase
|
||||
/// <returns>Binary stream when available.</returns>
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(MetaOnlyResponse), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> GetAsync([FromRoute] string id, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await sender.Send(new GetDocumentQuery(id), cancellationToken);
|
||||
|
||||
@@ -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.Domain.Closing;
|
||||
using DigitalData.TaskFlow.Domain.Common;
|
||||
using DigitalData.TaskFlow.Domain.Workflows;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -23,15 +21,26 @@ 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(ApiEnvelope<WorkflowSourcesResponse>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ApiEnvelope<WorkflowSourcesResponse>>> GetAsync(
|
||||
[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);
|
||||
return Ok(response);
|
||||
|
||||
var sources = response.Data?.Sources
|
||||
.Cast<object>()
|
||||
.ToList()
|
||||
?? [];
|
||||
|
||||
return Ok(new WorkflowsResponse
|
||||
{
|
||||
Meta = response.Meta,
|
||||
Sources = sources
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,13 +53,14 @@ public sealed class WorkflowsController(ISender sender) : ControllerBase
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>Close result envelope.</returns>
|
||||
[HttpPost("{wisagId:int}/{source}/{processId:int}/closing")]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<CloseWorkflowResult>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status409Conflict)]
|
||||
[ProducesResponseType(typeof(ApiEnvelope<object>), StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ApiEnvelope<CloseWorkflowResult>>> CloseAsync(
|
||||
[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,
|
||||
@@ -66,6 +76,9 @@ public sealed class WorkflowsController(ISender sender) : ControllerBase
|
||||
request.RejectionReasonId);
|
||||
|
||||
var response = await sender.Send(command, cancellationToken);
|
||||
return Ok(response);
|
||||
return Ok(new MetaOnlyResponse
|
||||
{
|
||||
Meta = response.Meta
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user