From 03498275d7b728bb5dcfd5e5204042a181021a89 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 27 Nov 2025 17:05:12 +0100 Subject: [PATCH] Implement BodyQueryBehavior and add SQL Server support Updated BodyQueryBehavior to process BodyQuery using the IRecDbContext dependency. Added logic to execute SQL queries via FromSqlRaw and assign results to the action's Body property. Removed placeholder NotImplementedException. Added Microsoft.EntityFrameworkCore.SqlServer package to ReC.Application.csproj to enable SQL Server database operations. --- .../Common/Behaviors/BodyQueryBehavior.cs | 15 +++++++++++---- src/ReC.Application/ReC.Application.csproj | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs index a404a43..77ed91c 100644 --- a/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs +++ b/src/ReC.Application/Common/Behaviors/BodyQueryBehavior.cs @@ -1,14 +1,21 @@ using MediatR; using ReC.Application.Common.Dto; +using ReC.Application.Common.Interfaces; +using Microsoft.EntityFrameworkCore; namespace ReC.Application.Common.Behaviors; -public class BodyQueryBehavior : IPipelineBehavior +public class BodyQueryBehavior(IRecDbContext dbContext) : IPipelineBehavior where TRecAction : RecActionDto { - public Task Handle(TRecAction action, RequestHandlerDelegate next, CancellationToken cancel) + public async Task Handle(TRecAction action, RequestHandlerDelegate next, CancellationToken cancel) { - // Logic to process the body query can be added here - throw new NotImplementedException("BodyQueryBehavior is not implemented yet."); + if (action.BodyQuery is null) + return await next(cancel); + + var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel); + action.Body = result?.RawBody; + + return await next(cancel); } } diff --git a/src/ReC.Application/ReC.Application.csproj b/src/ReC.Application/ReC.Application.csproj index 6cc1027..d5f5270 100644 --- a/src/ReC.Application/ReC.Application.csproj +++ b/src/ReC.Application/ReC.Application.csproj @@ -13,6 +13,7 @@ +