Here is the route corresponding to my controller method :
GET /my-resources controllers.MyResourceController.list(from: String ?= null, pageSize: Integer ?= null, sort: String ?= null)
I have no problem to use from
, pageSize
and sort
parameters in my query but I can't find how to do with filters.
I'd like to be able to filter every field of the entity but I want to find a way to avoid adding each property of my entity in the route (i.e. : code, name, description...)
Kind of call that should work :
https://myapi.com/my-resources?sort=name,description&name=MyName&description=Blablabla
In my controller, I apply filters on my database query by browsing request().queryString()
.
So my question is how to add a query string parameters in FakeRequest
in order to test my controller ?
If you have a better approach to pass filters in the request, do not hesitate.
Thanks
Query string is parsed from the URI, that you provide to your FakeRequest, so you can create FakeRequest like this:
FakeRequest(GET, "/my-resources?sort=name,description&name=MyName&description=Blablabla")
And it would work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With