ManagedObjectController<InstanceType extends ManagedObject> class

A Controller 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 Controller 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

  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 /
  • PUT /
  • DELETE /
  • POST /
  • GET /

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 ResourceController will accept.
getter/setter pairinherited
hashCode int
The hash code for this object.
no setterinherited
logger Logger
An instance of the 'liquidart' logger.
no setterinherited
nextController Controller?
Receives requests that this controller does not respond to.
no setterinherited
pathVariables Map<String, String>
Parameters parsed from the URI of the request, if any exist.
no setterinherited
policy CORSPolicy?
The CORS policy of this controller.
getter/setter pairinherited
recycledState Null
Returns state information that is reused across instances of this type.
no setterinherited
request Request?
The request being processed by this ResourceController.
getter/setter pairinherited
responseContentType ContentType
The default content type of responses from this ResourceController.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

applyCORSHeadersIfNecessary(Request req, Response resp) → void
inherited
createObject() Future<Response>
deleteObject(String id) Future<Response>
didAddToChannel() → void
Lifecycle callback, invoked after added to channel, but before any requests are served.
inherited
didDecodeRequestBody(RequestBody body) → void
Callback to indicate when a request body has been processed.
inherited
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.
documentComponents(APIDocumentContext context) → void
Tells this object to add its components to context.
inherited
documentOperationDescription(APIDocumentContext context, Operation operation) String?
Returns a documented description for operation.
inherited
documentOperationParameters(APIDocumentContext context, Operation operation) List<APIParameter?>
Returns a documented list of APIParameter for operation.
inherited
documentOperationRequestBody(APIDocumentContext context, Operation operation) APIRequestBody?
Returns a documented request body for operation.
override
documentOperationResponses(APIDocumentContext context, Operation operation) Map<String, APIResponse>
Returns a map of possible responses for operation.
override
documentOperations(APIDocumentContext context, String route, APIPath path) Map<String, APIOperation>
Tells this object to return all APIOperations it handles.
override
documentOperationSummary(APIDocumentContext context, Operation operation) String?
Returns a documented summary for operation.
inherited
documentOperationTags(APIDocumentContext context, Operation operation) List<String>
Returns a list of tags for operation.
inherited
documentPaths(APIDocumentContext context) Map<String, APIPath>
Tells this object to return all APIPaths it handles.
inherited
getObject(String id) Future<Response>
getObjects({int count = 0, int offset = 0, String? pageBy, String? pageAfter, String? pagePrior, List<String>? sortBy}) Future<Response>
handle(Request request) FutureOr<RequestOrResponse>
The primary request handling method of this object.
inherited
handleError(Request request, dynamic caughtValue, StackTrace trace) Future
Sends an HTTP response for a request that yields an exception or error.
inherited
Links a controller to the receiver to form a request channel.
inherited
linkFunction(FutureOr<RequestOrResponse?> handle(Request request)) Linkable
Links a function controller to the receiver to form a request channel.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
receive(Request req) Future
Delivers req to this instance to be processed.
inherited
restore(Null state) → void
Provides a new instance of this type with the recycledState of this type.
inherited
toString() String
A string representation of this object.
inherited
updateObject(String id) Future<Response>
willDecodeRequestBody(RequestBody body) → void
Callback invoked prior to decoding a request body.
inherited
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.
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
willUpdateObjectWithQuery(Query<InstanceType> query) FutureOr<Query<InstanceType>>
Executed prior to a update query being executed.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

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