Add Invoked filter to ReadRecActionQuery handler

Introduced a nullable `Invoked` property in `ReadRecActionQueryBase`
to enable conditional filtering of actions based on `Root.OutRes`.
Added a `ToReadQuery` method for easier query conversion.

Refactored `ReadRecActionQueryHandler` to apply dynamic filtering
based on the `Invoked` property:
- `true`: Filters actions with non-null `Root.OutRes`.
- `false`: Filters actions with null `Root.OutRes`.
- `null`: No additional filtering applied.

Replaced hardcoded filtering logic with the new dynamic approach.
This commit is contained in:
tekh 2025-12-04 14:50:25 +01:00
parent 0f3fd320b0
commit 34d0741ac8

View File

@ -12,6 +12,8 @@ public record ReadRecActionQueryBase
{
public long ProfileId { get; init; }
public bool? Invoked { get; set; } = null;
public ReadRecActionQuery ToReadQuery() => new(this);
}
@ -26,7 +28,12 @@ public class ReadRecActionQueryHandler(IRepository<RecActionView> repo, IMapper
{
public async Task<IEnumerable<RecActionDto>> Handle(ReadRecActionQuery request, CancellationToken cancel)
{
var actions = await repo.Where(act => act.ProfileId == request.ProfileId).Where(act => act.Root!.OutRes != null).ToListAsync(cancel);
var query = repo.Where(act => act.ProfileId == request.ProfileId);
if (request.Invoked is bool invoked)
query = invoked ? query.Where(act => act.Root!.OutRes != null) : query.Where(act => act.Root!.OutRes == null);
var actions = await query.ToListAsync(cancel);
if(actions.Count == 0)
throw new NotFoundException($"No actions found for the profile {request.ProfileId}.");