From 38f91aae847a69d4a85ee8cafaa7175cafd9c480 Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 16 Apr 2026 10:20:18 +0200 Subject: [PATCH] Add AnyResultViewQuery to check for matching ResultView Introduced AnyResultViewQuery and its handler to determine if any ResultView entity exists matching optional filters (Id, ActionId, ProfileId, BatchId). The handler builds the query dynamically and uses AnyAsync for efficient existence checks. --- .../Results/Queries/AnyResultViewQuery.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/ReC.Application/Results/Queries/AnyResultViewQuery.cs diff --git a/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs b/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs new file mode 100644 index 0000000..567cd4e --- /dev/null +++ b/src/ReC.Application/Results/Queries/AnyResultViewQuery.cs @@ -0,0 +1,35 @@ +using DigitalData.Core.Abstraction.Application.Repository; +using MediatR; +using Microsoft.EntityFrameworkCore; +using ReC.Domain.Views; + +namespace ReC.Application.Results.Queries; + +public record AnyResultViewQuery( + long? Id = null, + long? ActionId = null, + long? ProfileId = null, + string? BatchId = null +) : IRequest; + +public class AnyResultViewQueryHandler(IRepository repo) : IRequestHandler +{ + public Task Handle(AnyResultViewQuery request, CancellationToken cancel) + { + var q = repo.Query; + + if(request.Id is long id) + q = q.Where(rv => rv.Id == id); + + if(request.ActionId is long actionId) + q = q.Where(rv => rv.ActionId == actionId); + + if(request.ProfileId is long profileId) + q = q.Where(rv => rv.ProfileId == profileId); + + if(request.BatchId is string batchId) + q = q.Where(rv => rv.BatchId == batchId); + + return q.AnyAsync(cancel); + } +} \ No newline at end of file