Refactor ReadOutResQuery and add query handler
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.
This commit is contained in:
parent
4ed080f58a
commit
2de0b5bfa3
@ -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<OutResDto>
|
||||
{
|
||||
public long? ProfileId { get; set; }
|
||||
public long? ProfileId { get; init; }
|
||||
|
||||
public long? ActionId { get; set; }
|
||||
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);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user