Say for example you receive an API request to list Users as a JSON object. Pretty straightforward to do in the controller class.
Users::all()
Now, the client can pass all sorts of optional arguments in the request, e.g.
minAge
, maxAge
, gender
etc…
These will require additional where
conditions in the query. The challenge is to do it optimally, and concisely. Insert the relevant where
statements only if the relevant parameters are supplied in the request.
I am looking for examples of handling this design problem in a good way.
EDIT: The aim is also efficiency, minimizing number of database roundtrips.
Thanks