wmiys / api.alpha

Api for the the backend
0 stars 0 forks source link

Setup request sorting #113

Closed rrickgauer closed 3 years ago

rrickgauer commented 3 years ago

Setup a sorting parameter for requests that return multiple objects

rrickgauer commented 3 years ago

Requests that should allow for sorting:

Sort by having :?sort=field_name:[asc|desc]. If no sort type (asc, desc) is specified, asc is used. Or, asc is the default sort type.

Each resource that has the option to sort needs to have a default field to sort on. This is for when no sort paramter is specified in the URL.

One approach to handle this is to make a request sort class. The data members could be:

Most classes, Product for example, have a static method that gets called to retrieve all of a user's products. I can create a static property that can be the default sort field for each class. That way it can have a default sort field, if one wasn't provided.