Refactor InsertResultProcedure to use MediatR handler
Refactored InsertResultProcedure by removing its ToObjectProcedure method and introducing InsertResultProcedureHandler, which implements IRequestHandler and delegates object insertion via MediatR's ISender. This shifts conversion logic from the record to the handler and improves separation of concerns.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
using MediatR;
|
||||||
|
using ReC.Application.Common.Procedures.InsertProcedure;
|
||||||
|
|
||||||
namespace ReC.Application.Results.Commands;
|
namespace ReC.Application.Results.Commands;
|
||||||
|
|
||||||
@@ -10,13 +11,16 @@ public record InsertResultProcedure : IInsertProcedure
|
|||||||
public string? Body { get; set; }
|
public string? Body { get; set; }
|
||||||
public string? Info { get; set; }
|
public string? Info { get; set; }
|
||||||
public string? Error { get; set; }
|
public string? Error { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public InsertObjectProcedure ToObjectProcedure(string? addedWho = null)
|
public class InsertResultProcedureHandler(ISender sender) : IRequestHandler<InsertResultProcedure, long>
|
||||||
|
{
|
||||||
|
public async Task<long> Handle(InsertResultProcedure request, CancellationToken cancel)
|
||||||
{
|
{
|
||||||
return new InsertObjectProcedure
|
return await sender.Send(new InsertObjectProcedure
|
||||||
{
|
{
|
||||||
Entity = "RESULT",
|
Entity = "RESULT",
|
||||||
Result = this
|
Result = request
|
||||||
}.AddedBy(addedWho ?? "Rec.API");
|
}, cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user