How do we hookup a custom IQueryable
logic to the filter/sort configurations?
#3176
-
We have a few use cases that will need custom public class Time
{
public DateTime? In { get; set; }
public DateTime? Out { get; set; }
}
public class Employee
{
public ICollection<Time> Times { get; } = new HashSet<Time>();
}
public enum Status
{
In,
Out
} We'd like the client to be able to do
I started with the following public class EmployeeFilterInputType : FilterInputType<Employee>
{
protected override void Configure(IFilterInputTypeDescriptor<Employee> descriptor)
{
descriptor
.Field("status")
.Type<EnumType<Status>>()
.Extend()
.OnBeforeCreate(_ => _.Handler = new StatusHandler());
}
public class StatusHandler : IFilterFieldHandler
{
public bool CanHandle(ITypeCompletionContext context, IFilterInputTypeDefinition typeDefinition, IFilterFieldDefinition fieldDefinition)
=> throw new NotImplementedException();
// TODO: hook this logic to the filter
public IQueryable<Employee> Handle(
IQueryable<Employee> employees,
Status status) =>
status == Status.In
? employees.Where(_ => _.Times.OrderByDescending(_ => _.Out ?? _.In).First().Out == null)
: employees.Where(_ => _.Times.OrderByDescending(_ => _.Out ?? _.In).First().Out != null);
}
} I'll continue looking into this and post my solution if I'm able to solve it but any help would be greatly appreciated! Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You are lost in how to apply the FilterInput types or what is your exact issue? |
Beta Was this translation helpful? Give feedback.
-
I think I got it.. Basically, there is a Everything stays the same with the sample on first post above except for the
|
Beta Was this translation helpful? Give feedback.
I think I got it.. Basically, there is a
QueryableDefaultFieldHandler
that we can inherit and overrideTryHandleEnter
instead of implementingIFilterFieldHandler
..Everything stays the same with the sample on first post above except for the
StatusHandler
implementation which is now: