From 2de0b5bfa38e621d92866e2b2c2c465e4bbdd7ba Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 4 Dec 2025 10:03:57 +0100 Subject: [PATCH] Refactor ReadOutResQuery and add query handler Refactored `ReadOutResQuery` to a record type implementing `IRequest` for MediatR. Introduced `ReadOutResHandler` to handle the query, leveraging `IRepository` and `IMapper` for database access and mapping. Added support for filtering by `ActionId` and asynchronous query execution. Streamlined design by moving `ProfileId` and `ActionId` to immutable `init` properties in the record. --- .../OutResults/Queries/ReadOutResQuery.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/ReC.Application/OutResults/Queries/ReadOutResQuery.cs b/src/ReC.Application/OutResults/Queries/ReadOutResQuery.cs index a933412..46a58a3 100644 --- a/src/ReC.Application/OutResults/Queries/ReadOutResQuery.cs +++ b/src/ReC.Application/OutResults/Queries/ReadOutResQuery.cs @@ -1,8 +1,30 @@ -namespace ReC.Application.OutResults.Queries; +using AutoMapper; +using DigitalData.Core.Abstraction.Application.Repository; +using MediatR; +using Microsoft.EntityFrameworkCore; +using ReC.Application.Common.Dto; +using ReC.Domain.Entities; -public class ReadOutResQuery +namespace ReC.Application.OutResults.Queries; + +public record ReadOutResQuery : IRequest +{ + public long? ProfileId { get; init; } + + public long? ActionId { get; init; } +} + +public class ReadOutResHandler(IRepository repo, IMapper mapper) : IRequestHandler { - public long? ProfileId { get; set; } + public async Task Handle(ReadOutResQuery request, CancellationToken cancel) + { + var q = repo.Query; + + if(request.ActionId is long actionId) + q = q.Where(res => res.ActionId == actionId); + + var dtos = await q.ToListAsync(cancel); - public long? ActionId { get; set; } + return mapper.Map(dtos); + } } \ No newline at end of file