-
Notifications
You must be signed in to change notification settings - Fork 141
Closed
Description
I would like to be able to (optionally) explicitly specify which properties are used for the queries instead of using the Sieve attribute. Ideally, this "specification" would also allow the definition of a mapping between a query term to an actual property on the model class.
My arguments supporting this request:
- Different APIs for the same underlying model may support filtering or sorting on different properties.
- By directly using names of properties in my model classes, the domain is coupled to the query endpoint. This e.g. means that it is not possible to rename a property on a model class without a breaking change in the API.
- I don't want to "pollute" my domain classes with attributes that are only relevant for querying them via a REST API.
Here is an example of how the changed call to SieveProcessor could look like:
` var result = _dbContext.Posts.AsNoTracking();
var sieveProperties = new[]
{
SieveProperty<Post>.For(_ => _.Title, Allow.Filter, "name"),
SieveProperty<Post>.For(_ => _.CommentCount, Allow.SortAndFilter),
SieveProperty<Post>.For(_ => _.LikeCount, Allow.Sort),
SieveProperty<Post>.For(_ => _.DateCreated, Allow.SortAndFilter),
};
result = _sieveProcessor.ApplyAll(sieveModel, result, sieveProperties);
return Json(result.ToList());
I have implemented a draft of the necessary changes and will open a PR. Feedback is welcome!
BTW: Great work so far!
Biarity and saurabhlogward
Metadata
Metadata
Assignees
Labels
No labels