Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add query string parameter to FakeRequest in Play Framework 2.3?

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

like image 448
c4k Avatar asked Dec 29 '14 11:12

c4k


1 Answers

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.

like image 64
mavarazy Avatar answered Sep 19 '22 21:09

mavarazy