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.
This commit is contained in:
tekh 2025-11-27 17:05:12 +01:00
parent f8581deaf9
commit 03498275d7
2 changed files with 12 additions and 4 deletions

View File

@ -1,14 +1,21 @@
using MediatR; using MediatR;
using ReC.Application.Common.Dto; using ReC.Application.Common.Dto;
using ReC.Application.Common.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace ReC.Application.Common.Behaviors; namespace ReC.Application.Common.Behaviors;
public class BodyQueryBehavior<TRecAction> : IPipelineBehavior<TRecAction, Unit> public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineBehavior<TRecAction, Unit>
where TRecAction : RecActionDto where TRecAction : RecActionDto
{ {
public Task<Unit> Handle(TRecAction action, RequestHandlerDelegate<Unit> next, CancellationToken cancel) public async Task<Unit> Handle(TRecAction action, RequestHandlerDelegate<Unit> next, CancellationToken cancel)
{ {
// Logic to process the body query can be added here if (action.BodyQuery is null)
throw new NotImplementedException("BodyQueryBehavior is not implemented yet."); return await next(cancel);
var result = await dbContext.BodyQueryResults.FromSqlRaw(action.BodyQuery).FirstOrDefaultAsync(cancel);
action.Body = result?.RawBody;
return await next(cancel);
} }
} }

View File

@ -13,6 +13,7 @@
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" /> <PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
<PackageReference Include="MediatR" Version="13.1.0" /> <PackageReference Include="MediatR" Version="13.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.11" />
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" /> <PackageReference Include="Microsoft.Extensions.Http" Version="10.0.0" />
</ItemGroup> </ItemGroup>