-
Notifications
You must be signed in to change notification settings - Fork 23
Create webapi action filter for filtering IQueryables #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
8394ebe to
8fc80db
Compare
The last bullet here bothers me, but there's not currently a solution in the spec for explicitly filtering on null as a value. So, I've opened an issue on it, we'll see if it gets any attention. The main use case that strikes me as a problem is querying for an empty string value...this being the implementation, that's not possible. If we go the other way for strings, it's not possible to query for nulls. Tricky.
Yeah, it's a pity this will be a tougher nut to crack, which I hadn't really considered...and darn it the spec's examples are exactly that. We'll merge as is, but we're going to want this too eventually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it has two typos that cause the test to fail, should this be:
var returnedArray = GetArray<Dummy>("http://api.example.com/dummies?stringField=String value 2&enumField=3");
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you're right. I'll fix that.
|
Also, is there a reason you put this in JSONAPI.EntityFramework? I don't see any EF specific code, and in theory any ApiController's Get method could return an IQueryable that should work with this code, I think...am I missing something in the generics gymnastics that assumes an EF-backed IQueryable? |
|
One last question: any objection to naming it I'm also thinking ahead to sorting, which I'm guessing will become another ActionFilter probably named |
|
Or, Okay I'm done. |
You're right, I was being stupid. For some reason I thought that all the extension methods like Where are defined by EF. But that doesn't make any sense. I just looked them up and of course they're in System.Linq. I'll move the filter to JSONAPI. |
I have no objection to renaming it to reflect its role in filtering. The words ActionFilter might be redundant too. FilteringAttribute might be too generic. JsonApiFilteringAttribute? QueryFilteringAttribute? FilteringQueryableAttribute? Naming stuff is hard... |
Oh, I guess I should have read this before I commented. Yeah, this is better. |
8fc80db to
41a2b79
Compare
41a2b79 to
5de86dc
Compare
|
@SphtKr New diff is up. |
Create webapi action filter for filtering IQueryables
|
Supports #14, but let's see if we can get object IDs to work before we close that one. |
This adds a new action filter called JsonApiQueryableActionFilterAttribute that can be inserted into the WebAPI pipeline. It detects if the object content is an IQueryable<>. If it is, the filter performs exact-match filtering according to the json-api spec.
Filtering is supported for the following types:
as well as their nullable counterparts. There is not yet support for linked IDs.
A few notes on the behavior:
GET /people?firstName=John&lastName=Doewill yield all people whose first name is John AND last name is Doe.GET /people?firstName=John&firstName=Bill, the behavior is undefined.