ManagedObjectController<InstanceType extends ManagedObject> class Null safety

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

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 non-existent method or property is accessed.
inherited
receive(Request req) Future?
Delivers req to this instance to be processed.
inherited
restore(void state) → void
Provides a 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.