Skip to content

Latest commit

 

History

History
96 lines (61 loc) · 2.48 KB

GLOBAL_CONTROLLER.md

File metadata and controls

96 lines (61 loc) · 2.48 KB

Global Controller

Implementation

The Global Controller uses inheritance to test defaults for all the functionality need to complete your resources. Restrict routes through your resource decalration.

You can over write any of the methods in the global controller within your parent controller that inherits the GlobalController.

This supports all schemas and only handles resources for a single model.

Default Resources

All resource methods are made by default.

Index Method

Index get default will return a limit of 25 and offset of 0 and page of 1. Index uses offset to create pages.

Querystings Options:

  • Pagination
First page = ?page=1&limit=25&offset=0
Second page = ?page=2&limit=25&offset=0
Etc...
  • Associations

You can grab the associated tables with include with comma separation. They will be formatted in the Global Controller. Provide a model assoication as defined.

?include=(1st-model-name),(2nd-model-name)
  • Custom Wheres

You grab a custom where with key:value pairs set based on JSON formatting. Options are separated by commas and key:values are separated by semi-colons.

?where=(key:value),(key:value)
  • Order

You grab by the order of any key in the model with key:value pairs that are comma separated. The value can only be DESC or ASC.

?order=(key:value),(key:value)

Show Method

Querystring Options:

  • Associations

You can grab the associated tables with include with comma separation. They will be formatted in the Global Controller. Provide a model assoication as defined.

?include=(1st-model-name),(2nd-model-name)

Returns the row by id of a model in a single object returned.

Create Method

This handles your create with any keys you allow with your create_params method in your controller. By default it is every key in the model with id, created_at, or updated_at Returning a single object of the row created.

Update Method

This handles your update with any keys you allow with your update_params method in your controller. By default it is every key in the model with id, created_at, or updated_at Returning a single object of the row created.

Destroy Method

Returns no content and deletes by id of a model.

Overwriting Default Resources (For custom methods)

Just declare the resource method name in the parent controller and it will over write the default in Global Controller.

Changes in the Global Controller will change all of the controllers.