lucee.Componentcoldbox.system.FrameworkSupertype
coldbox.system.EventHandler
coldbox.system.RestHandler
cborm.models.resources.BaseHandler
contentbox.modules.contentbox-api.modules.contentbox-api-v1.handlers.baseHandler
This is our base handler for our API which is bassed off the cborm resources base handler.
## Pre-Requisites
- You will be injecting Virtual Entity services
- Your entities need to inherit from ActiveEntity
- You will need to register the routes using ColdBox resources()
method
- You will need mementifier active
## Requirements
In order for this to work, you will create a handler that inherits from this base
and make sure that you inject the appropriate virtual entity service using the variable name: ormService
Also populate the variables as needed
component extends="BaseOrmResource"{ // Inject the correct virtual entity service to use property name="ormService" inject="RoleService" property name="ormService" inject="PermissionService" // The default sorting order string: permission, name, data desc, etc. variables.sortOrder = ""; // The name of the entity this resource handler controls. Singular name please. variables.entity = "Permission"; }That's it! All resource methods:
index, create, show, update, delete
will be implemented for you.
You can create more actions or override them as needed.
Property Summary | ||||
---|---|---|---|---|
type | property | default | serializable | required |
any
|
cb
|
true
|
false
|
|
any
|
settings
|
true
|
false
|
|
any
|
siteService
|
true
|
false
|
Method Summary | |
---|---|
private any
|
autoCast(any propertyName, any value)
Coverts a value to the correct javaType for the property passed in. |
any
|
create([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])
Create a resource. |
any
|
delete([any event], [any rc], [any prc], [string deleteMethod='[runtime expression]'])
Delete a resource by id or slug. |
private any
|
getByIdOrSlugOrFail(any id, any prc)
This utility tries to get the incoming resource by id or slug or fails. |
private any
|
getMaxRows([any event='[runtime expression]'])
Get the max number of rows to retrieve according to global settings. |
private any
|
getPageOffset([any page='1'])
Calculate the starting offset for the incoming page. |
private any
|
getSiteByIdOrSlugOrFail(any id)
This utility tries to get a site by id or slug. |
any
|
index([any event], [any rc], [any prc], [any criteria], [struct results])
Display all resource records with pagination. |
private any
|
newCriteria([boolean useQueryCaching='false'], [string queryCacheRegion=''], [any datasource])
Get a brand new criteria builder object. |
any
|
show([any event], [any rc], [any prc])
Display a resource by incoming ID or slug. |
any
|
update([any event], [any rc], [any prc], [struct populate='[runtime expression]'], [struct validate='[runtime expression]'], [string saveMethod='[runtime expression]'])
Update a resource. |
Methods inherited from class cborm.models.resources.BaseHandler |
---|
None |
Methods inherited from class coldbox.system.RestHandler |
---|
aroundHandler, onAnyOtherException, onAuthenticationFailure, onAuthorizationFailure, onEntityNotFoundException, onError, onExpectationFailed, onInvalidHTTPMethod, onInvalidRoute, onMissingAction, onValidationException |
Methods inherited from class coldbox.system.EventHandler |
---|
_actionExists, _actionMetadata, _privateInvoker, init, onHandlerDIComplete |
Methods inherited from class coldbox.system.FrameworkSupertype |
---|
announce, announceInterception, async, back, externalView, forAttribute, getCache, getCachebox, getColdBoxSetting, getController, getDateTimeHelper, getEnv, getFlash, getFlow, getInstance, getIsoTime, getJsonUtil, getLog, getLogBox, getModuleConfig, getModuleSettings, getRenderer, getRequestCollection, getRequestContext, getRootWireBox, getSetting, getSystemProperty, getSystemSetting, getUserSessionIdentifier, getWirebox, ifNull, ifPresent, inDebugMode, includeUDF, isDevelopment, isProduction, isTesting, layout, listen, loadApplicationHelpers, locateDirectoryPath, locateFilePath, persistVariables, populate, populateModel, relocate, renderExternalView, renderLayout, renderview, runEvent, runRoute, setCachebox, setController, setEnv, setFlash, setFlow, setJsonUtil, setLog, setLogBox, setSetting, setWirebox, settingExists, throwIf, throwUnless, toJson, unless, view, when |
Methods inherited from class lucee.Component |
---|
None |
Property Detail |
---|
access
- publicrequired
- falsereturntype
- anyinject
- CBHelper@contentboxserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- coldbox:moduleSettings:cbormserializable
- trueaccess
- publicrequired
- falsereturntype
- anyinject
- siteService@contentboxserializable
- trueMethod Detail |
---|
Coverts a value to the correct javaType for the property passed in.
autoCast
in class
cborm.models.resources.BaseHandler
propertyName
- The property namevalue
- The property valueCreate a resource
create
in class
cborm.models.resources.BaseHandler
event
rc
prc
populate
validate
saveMethod
Delete a resource by id or slug
delete
in class
cborm.models.resources.BaseHandler
event
rc
prc
deleteMethod
This utility tries to get the incoming resource by id or slug or fails
id
- The id/slug identifier to retrieve the entityprc
- The ColdBox PRCGet the max number of rows to retrieve according to global settings or passed in through RC
getMaxRows
in class
cborm.models.resources.BaseHandler
event
Calculate the starting offset for the incoming page
getPageOffset
in class
cborm.models.resources.BaseHandler
page
- The page to lookup onThis utility tries to get a site by id or slug
id
Display all resource records with pagination GET /api/v1/{resource}
index
in class
cborm.models.resources.BaseHandler
event
rc
prc
criteria
- If you pass a criteria object, then we will use that instead of creating a new oneresults
- If you pass in a results struct, it must contain the following: { count:numeric, records: array of objects }Get a brand new criteria builder object
newCriteria
in class
cborm.models.resources.BaseHandler
useQueryCaching
- Activate query caching for the list operationsqueryCacheRegion
- The query cache region to use, which defaults to criterias.{entityName}datasource
Display a resource by incoming ID or slug
show
in class
cborm.models.resources.BaseHandler
event
rc
prc
Update a resource
update
in class
cborm.models.resources.BaseHandler
event
rc
prc
populate
validate
saveMethod