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:
parent
f8581deaf9
commit
03498275d7
@ -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<TRecAction> : IPipelineBehavior<TRecAction, Unit>
|
||||
public class BodyQueryBehavior<TRecAction>(IRecDbContext dbContext) : IPipelineBehavior<TRecAction, Unit>
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
<PackageReference Include="DigitalData.Core.Exceptions" Version="1.1.0" />
|
||||
<PackageReference Include="MediatR" Version="13.1.0" />
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user