Refactored `ReadOutResQuery` to a record type implementing `IRequest<OutResDto>` 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.
30 lines
834 B
C#
30 lines
834 B
C#
using AutoMapper;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using ReC.Application.Common.Dto;
|
|
using ReC.Domain.Entities;
|
|
|
|
namespace ReC.Application.OutResults.Queries;
|
|
|
|
public record ReadOutResQuery : IRequest<OutResDto>
|
|
{
|
|
public long? ProfileId { get; init; }
|
|
|
|
public long? ActionId { get; init; }
|
|
}
|
|
|
|
public class ReadOutResHandler(IRepository<OutRes> repo, IMapper mapper) : IRequestHandler<ReadOutResQuery, OutResDto>
|
|
{
|
|
public async Task<OutResDto> 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);
|
|
|
|
return mapper.Map<OutResDto>(dtos);
|
|
}
|
|
} |