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,5 +1,5 @@
|
||||
using DigitalData.TaskFlow.Application.Common.Exceptions;
|
||||
using DigitalData.TaskFlow.Application.Common.Factories;
|
||||
using DigitalData.TaskFlow.API.Contracts.Common;
|
||||
using DigitalData.TaskFlow.Domain.Common;
|
||||
using DigitalData.TaskFlow.Domain.Enums;
|
||||
using FluentValidation;
|
||||
@@ -31,7 +31,17 @@ public sealed class ExceptionHandlingMiddleware(RequestDelegate next, ILogger<Ex
|
||||
context.Response.StatusCode = apiException.StatusCode;
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
var response = ApiEnvelopeFactory.Create<object?>(null, apiException.MetaCode, apiException.Message);
|
||||
var response = new MetaOnlyResponse
|
||||
{
|
||||
Meta =
|
||||
[
|
||||
new MetaEntry
|
||||
{
|
||||
Code = (int)apiException.MetaCode,
|
||||
Message = apiException.Message
|
||||
}
|
||||
]
|
||||
};
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(response, JsonOptions));
|
||||
}
|
||||
catch (ValidationException validationException)
|
||||
@@ -44,7 +54,17 @@ public sealed class ExceptionHandlingMiddleware(RequestDelegate next, ILogger<Ex
|
||||
var message = validationException.Errors.FirstOrDefault()?.ErrorMessage
|
||||
?? "Ungultiger Request";
|
||||
|
||||
var response = ApiEnvelopeFactory.Create<object?>(null, MetaCode.InvalidRequest, message);
|
||||
var response = new MetaOnlyResponse
|
||||
{
|
||||
Meta =
|
||||
[
|
||||
new MetaEntry
|
||||
{
|
||||
Code = (int)MetaCode.InvalidRequest,
|
||||
Message = message
|
||||
}
|
||||
]
|
||||
};
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(response, JsonOptions));
|
||||
}
|
||||
catch (NotSupportedException notSupportedException)
|
||||
@@ -54,7 +74,17 @@ public sealed class ExceptionHandlingMiddleware(RequestDelegate next, ILogger<Ex
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
var response = ApiEnvelopeFactory.Create<object?>(null, MetaCode.InternalError, notSupportedException.Message);
|
||||
var response = new MetaOnlyResponse
|
||||
{
|
||||
Meta =
|
||||
[
|
||||
new MetaEntry
|
||||
{
|
||||
Code = (int)MetaCode.InternalError,
|
||||
Message = notSupportedException.Message
|
||||
}
|
||||
]
|
||||
};
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(response, JsonOptions));
|
||||
}
|
||||
catch (Exception exception)
|
||||
@@ -64,7 +94,17 @@ public sealed class ExceptionHandlingMiddleware(RequestDelegate next, ILogger<Ex
|
||||
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
var response = ApiEnvelopeFactory.Create<object?>(null, MetaCode.InternalError);
|
||||
var response = new MetaOnlyResponse
|
||||
{
|
||||
Meta =
|
||||
[
|
||||
new MetaEntry
|
||||
{
|
||||
Code = (int)MetaCode.InternalError,
|
||||
Message = "Interner Fehler"
|
||||
}
|
||||
]
|
||||
};
|
||||
await context.Response.WriteAsync(JsonSerializer.Serialize(response, JsonOptions));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user