Refactor query behaviors for execution tracking

Refactored `BodyQueryBehavior` and `HeaderQueryBehavior` to introduce explicit execution tracking with new properties (`BodyQueryExecuted` and `HeaderQueryExecuted`). Updated `RecActionDto` to include computed properties (`IsBodyQueryReturnedNoData` and `IsHeaderQueryReturnedNoData`) for clearer null-checking logic. Removed the `IsReturnedNoData` tuple for simplicity.

Updated `InvokeRecActionCommandHandler` to use the new `IsBodyQueryReturnedNoData` property. Improved logging for better diagnostics and clarified handling of null results in query behaviors.
This commit is contained in:
tekh 2025-12-01 10:10:41 +01:00
parent 29f0a82f0f
commit 90e2460716
4 changed files with 14 additions and 7 deletions

View File

@ -14,6 +14,9 @@ public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineB
return await next(cancel);
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).SingleOrDefaultAsync(cancel);
action.BodyQueryExecuted = true;
action.Body = result?.RawBody;
return await next(cancel);

View File

@ -17,12 +17,12 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
var result = await dbContext.HeaderQueryResults.FromSqlRaw(action.HeaderQuery).SingleOrDefaultAsync(cancel);
if(result?.RawHeader is null)
action.HeaderQueryExecuted = true;
if (result?.RawHeader is null)
{
logger?.LogWarning("Header query did not return a result or returned a null REQUEST_HEADER. Profile ID: {ProfileId}, Action ID: {ActionId}", action.ProfileId, action.ActionId);
action.IsReturnedNoData.HeaderQuery = true;
return await next(cancel);
}
@ -34,8 +34,6 @@ public class HeaderQueryBehavior<TRecAction>(IRecDbContext dbContext, ILogger<He
"Header JSON deserialization returned null. RawHeader: {RawHeader}, ProfileId: {ProfileId}, ActionId: {ActionId}",
result.RawHeader, action.ProfileId, action.ActionId);
action.IsReturnedNoData.HeaderQuery = true;
return await next(cancel);
}

View File

@ -54,13 +54,19 @@ public record RecActionDto
public string? HeaderQuery { get; init; }
public bool HeaderQueryExecuted { get; set; } = false;
public bool IsHeaderQueryReturnedNoData => HeaderQueryExecuted && HeaderQuery is null;
public Dictionary<string, string>? Headers { get; set; }
public string? BodyQuery { get; init; }
public string? Body { get; set; }
public (bool BodyQuery, bool HeaderQuery) IsReturnedNoData = (false, false);
public bool BodyQueryExecuted { get; set; } = false;
public bool IsBodyQueryReturnedNoData => BodyQueryExecuted && Body is null;
public string? PostprocessingQuery { get; init; }

View File

@ -45,7 +45,7 @@ public class InvokeRecActionCommandHandler(
using var reqBody = new StringContent(request.Body);
httpReq.Content = reqBody;
}
else if(request.BodyQuery is not null && !request.IsReturnedNoData.BodyQuery)
else if(request.BodyQuery is not null && !request.IsBodyQueryReturnedNoData)
{
logger?.LogWarning(
"Although BodyQuery returns null, the IsReturnedNoData variable has not been set to TRUE. " +