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:
2026-10-10 20:47:31 +02:00
parent 600374a6f0
commit 70e82567d8
14 changed files with 352 additions and 166 deletions

View File

@@ -36,6 +36,7 @@ public sealed class CloseWorkflowCommandValidator : AbstractValidator<CloseWorkf
private static readonly string[] AllowedSources = ["Ferdinand", "Contracts"];
private const int ApproveMethodId = 2;
private const int RejectMethodId = 3;
private const int BackToPerMethodId = 4;
/// <summary>
/// Initializes validation rules for <see cref="CloseWorkflowCommand"/>.
@@ -57,12 +58,12 @@ public sealed class CloseWorkflowCommandValidator : AbstractValidator<CloseWorkf
.WithMessage("Source must be one of the supported source systems.");
RuleFor(x => x.ClosingMethodId)
.Must(methodId => methodId is ApproveMethodId or RejectMethodId)
.Must(methodId => methodId is ApproveMethodId or RejectMethodId or BackToPerMethodId)
.WithMessage("Unbekannte closing_method_id");
RuleFor(x => x.Comment)
.NotEmpty()
.When(x => x.ClosingMethodId == RejectMethodId)
.When(x => x.ClosingMethodId is RejectMethodId or BackToPerMethodId)
.WithMessage("Kommentar ist fur diese closing_method Pflicht");
RuleFor(x => x.RejectionReasonId)

View File

@@ -50,14 +50,12 @@ public sealed class GetWorkflowsQueryHandler(IWorkflowRepository workflowReposit
return ApiEnvelopeFactory.Create(data, MetaCode.NoAccess);
}
var hasListingData = data.Sources
.SelectMany(source => source switch
{
FerdinandSourceBlock ferdinand => ferdinand.Listing,
ContractsSourceBlock contracts => contracts.Listing,
_ => []
})
.Any();
var hasListingData = data.Sources.Any(source => source switch
{
FerdinandSourceBlock ferdinand => ferdinand.Listing.Count > 0,
ContractsSourceBlock contracts => contracts.Listing.Count > 0,
_ => false
});
if (!hasListingData)
{

View File

@@ -1,5 +1,8 @@
namespace DigitalData.TaskFlow.Domain.Workflows;
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// Represents workflow data for the Contracts source system.
/// </summary>
@@ -8,30 +11,30 @@ public sealed record ContractsSourceBlock : SourceBlock
/// <summary>
/// Gets available approval profiles.
/// </summary>
public required IReadOnlyList<ProfileItem> Profiles { get; init; }
[JsonPropertyName("profile")]
public required IReadOnlyList<JsonElement> Profile { get; init; }
/// <summary>
/// Gets workflow listing items.
/// </summary>
public required IReadOnlyList<WorkflowListingItem> Listing { get; init; }
[JsonPropertyName("Listing")]
public required IReadOnlyList<JsonElement> Listing { get; init; }
/// <summary>
/// Gets already executed approvals.
/// </summary>
public required IReadOnlyList<ApprovalItem> Approvals { get; init; }
[JsonPropertyName("approvals")]
public required IReadOnlyList<JsonElement> Approvals { get; init; }
/// <summary>
/// Gets document references for workflows.
/// </summary>
public required IReadOnlyList<DocumentReferenceItem> Documents { get; init; }
[JsonPropertyName("document")]
public required IReadOnlyList<JsonElement> Document { get; init; }
/// <summary>
/// Gets available closing methods for workflows.
/// </summary>
public required IReadOnlyList<ClosingMethodItem> ClosingMethods { get; init; }
/// <summary>
/// Gets available rejection reasons for rejection-type methods.
/// </summary>
public required IReadOnlyList<RejectionReasonItem> RejectionReasons { get; init; }
[JsonPropertyName("closing_method")]
public required IReadOnlyList<JsonElement> ClosingMethod { get; init; }
}

View File

@@ -1,5 +1,8 @@
namespace DigitalData.TaskFlow.Domain.Workflows;
using System.Text.Json;
using System.Text.Json.Serialization;
/// <summary>
/// Represents workflow data for the Ferdinand source system.
/// </summary>
@@ -8,30 +11,36 @@ public sealed record FerdinandSourceBlock : SourceBlock
/// <summary>
/// Gets available approval profiles.
/// </summary>
public required IReadOnlyList<ProfileItem> Profiles { get; init; }
[JsonPropertyName("profile")]
public required IReadOnlyList<JsonElement> Profile { get; init; }
/// <summary>
/// Gets workflow listing items.
/// </summary>
public required IReadOnlyList<WorkflowListingItem> Listing { get; init; }
[JsonPropertyName("Listing")]
public required IReadOnlyList<JsonElement> Listing { get; init; }
/// <summary>
/// Gets already executed approvals.
/// </summary>
public required IReadOnlyList<ApprovalItem> Approvals { get; init; }
[JsonPropertyName("approvals")]
public required IReadOnlyList<JsonElement> Approvals { get; init; }
/// <summary>
/// Gets document references for workflows.
/// </summary>
public required IReadOnlyList<DocumentReferenceItem> Documents { get; init; }
[JsonPropertyName("document")]
public required IReadOnlyList<JsonElement> Document { get; init; }
/// <summary>
/// Gets available closing methods for workflows.
/// </summary>
public required IReadOnlyList<ClosingMethodItem> ClosingMethods { get; init; }
[JsonPropertyName("closing_method")]
public required IReadOnlyList<JsonElement> ClosingMethod { get; init; }
/// <summary>
/// Gets available rejection reasons for rejection-type methods.
/// </summary>
public required IReadOnlyList<RejectionReasonItem> RejectionReasons { get; init; }
[JsonPropertyName("rejection_reason")]
public required IReadOnlyList<JsonElement> RejectionReason { get; init; }
}