ManagedObjectController<InstanceType extends ManagedObject> class

A RequestController that implements basic CRUD operations for a ManagedObject.

Instances of this class map a REST API call directly to a database Query. For example, this RequestController handles an HTTP PUT request by executing an update Query; the path variable in the request indicates the value of the primary key for the updated row and the HTTP request body are the values updated.

When routing to a ManagedObjectController, you must provide the following route pattern, where can be any string:

  router.route("/<name>/[:id]")

You may optionally use the static method ManagedObjectController.routePattern to create this string for you.

The mapping for HTTP request to action is as follows:

  • GET //:id -> Fetch Object by ID
  • PUT //:id -> Update Object by ID, HTTP Request Body contains update values.
  • DELETE //:id -> Delete Object by ID
  • POST / -> Create new Object, HTTP Request Body contains update values.
  • GET / -> Fetch instances of Object

You may use this class without subclassing, but you may also subclass it to modify the executed Query prior to its execution, or modify the returned Response after the query has been completed.

The HTTP response body is encoded according to responseContentType.

GET requests with no path parameter can take extra query parameters to modify the request. The following are the available query parameters:

  • count (integer): restricts the number of objects fetched to count. By default, this is null, which means no restrictions.
  • offset (integer): offsets the fetch by offset amount of objects. By default, this is null, which means no offset.
  • pageBy (string): indicates the key in which to page by. See Query.pageBy for more information on paging. If this value is passed as part of the query, either pageAfter or pagePrior must also be passed, but only one of those.
  • pageAfter (string): indicates the page value and direction of the paging. pageBy must also be set. See Query.pageBy for more information.
  • pagePrior (string): indicates the page value and direction of the paging. pageBy must also be set. See Query.pageBy for more information.
  • sortBy (string): indicates the sort order. The syntax is 'sortBy=key,order' where key is a property of InstanceType and order is either 'asc' or 'desc'. You may specify multiple sortBy parameters.
Inheritance

Constructors

ManagedObjectController([ManagedContext context ])
Creates an instance of a ManagedObjectController. [...]
ManagedObjectController.forEntity(ManagedEntity entity, [ ManagedContext context ])
Creates a new ManagedObjectController without a static type. [...]

Properties

acceptedContentTypes List<ContentType>
Types of content this HTTPController will accept. [...]
read / write, inherited
documentableChild APIDocumentable
Returns the next documentable object in a chain of documentable objects. [...]
read-only, inherited
hashCode int
The hash code for this object. [...]
read-only, inherited
logger Logger
An instance of the 'aqueduct' logger.
read-only, inherited
nextController RequestController
Receives requests that this controller does not respond to. [...]
read-only, inherited
pathVariables Map<String, String>
Parameters parsed from the URI of the request, if any exist. [...]
read-only, inherited
policy CORSPolicy
The CORS policy of this controller.
read / write, inherited
request Request
The request being processed by this HTTPController. [...]
read / write, inherited
responseContentType ContentType
The default content type of responses from this HTTPController. [...]
read / write, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

createObject() Future<Response>
@httpPost
deleteObject(String id) Future<Response>
@httpDelete
didDeleteObjectWithID(dynamic id) FutureOr<Response>
Executed after an object was deleted. [...]
didFindObject(InstanceType result) FutureOr<Response>
Executed after a fetch by ID query that found a matching instance. [...]
didFindObjects(List<InstanceType> objects) FutureOr<Response>
Executed after a list of objects has been fetched. [...]
didInsertObject(InstanceType object) FutureOr<Response>
Executed after an insert query is successful. [...]
didNotFindObject() FutureOr<Response>
Executed after a fetch by ID query that did not find a matching instance. [...]
didNotFindObjectToDeleteWithID(dynamic id) FutureOr<Response>
Executed when no object was deleted during a delete query. [...]
didNotFindObjectToUpdateWithID(dynamic id) FutureOr<Response>
Executed after an object not found during an update query. [...]
didUpdateObject(InstanceType object) FutureOr<Response>
Executed after an object was updated. [...]
documentRequestBodyForOperation(APIOperation operation) APIRequestBody
Returns all APIRequestBodys for operation.
documentResponsesForOperation(APIOperation operation) List<APIResponse>
getObject(String id) Future<Response>
@httpGet
getObjects({int count: 0, int offset: 0, String pageBy: null, String pageAfter: null, String pagePrior: null, List<String> sortBy: null }) Future<Response>
@httpGet
updateObject(String id) Future<Response>
@httpPut
willDeleteObjectWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to a delete query being executed. [...]
willFindObjectsWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to a fetch query being executed. [...]
willFindObjectWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to a fetch by ID query. [...]
willInsertObjectWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to an insert query being executed. [...]
willUpdateObjectWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to a update query being executed. [...]
applyCORSHeadersIfNecessary(Request req, Response resp) → void
inherited
didDecodeRequestBody(HTTPRequestBody decodedObject) → void
Callback to indicate when a request body has been processed. [...]
inherited
documentAPI(PackagePathResolver resolver) APIDocument
Returns an entire APIDocument describing an OpenAPI specification. [...]
inherited
documentOperations(PackagePathResolver resolver) List<APIOperation>
Returns all APIOperations this object knows about.
inherited
documentPaths(PackagePathResolver resolver) List<APIPath>
Returns all APIPath objects this instance knows about. [...]
inherited
documentSecuritySchemes(PackagePathResolver resolver) Map<String, APISecurityScheme>
Returns all APISecuritySchemes this instance knows about.
inherited
generate(RequestController instantiator()) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
handleError(Request request, dynamic caughtValue, StackTrace trace) Future<bool>
Sends an HTTP response for a request that yields an exception or error. [...]
inherited
listen(FutureOr<RequestOrResponse> process(Request request)) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
pipe(RequestController next) RequestController
Sets the nextController that will receive a request after this one. [...]
inherited
processRequest(Request req) Future<RequestOrResponse>
Overridden by subclasses to modify or respond to an incoming request. [...]
inherited
receive(Request req) Future
Delivers req to this instance to be processed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited
willDecodeRequestBody(HTTPRequestBody body) → void
Callback invoked prior to decoding a request body. [...]
inherited
willProcessRequest(Request req) FutureOr<RequestOrResponse>
Executed prior to handling a request, but after the request has been set. [...]
inherited
willSendResponse(Response response) → void
Executed prior to Response being sent. [...]
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Methods

routePattern(String name) String
Returns a route pattern for using ManagedObjectControllers. [...]