build method

  1. @override
Component build(
  1. BuildContext context
)
override

Implementation

@override
Component build(BuildContext context) {
  var result = AccessPoint((request, ctx) async {
    var method = request.method;
    Access access;

    if (method == null) {
      throw MethodNotAllowedException();
    } else if (method == Methods.POST) {
      if (request.body is! JsonBody) {
        throw BadRequests();
      }
      access = _create(request, ctx);
    } else if (method == Methods.GET) {
      if (request.path.notProcessedValues.isEmpty) {
        access = _readList(request);
      } else {
        access = _read(request);
      }
    } else if (method == Methods.PUT || method == Methods.PATCH) {
      if (request.path.notProcessedValues.isEmpty) {
        throw UnimplementedError();
      } else {
        access = _update(request);
      }
    } else if (method == Methods.DELETE) {
      if (request.path.notProcessedValues.isEmpty) {
        throw UnimplementedError();
      } else {
        access = _delete(request);
      }
    } else {
      throw MethodNotAllowedException();
    }
    return AccessEvent(
      access: access,
      request: request,
    );
  });
  return Route(route, handleUnknownAsRoot: true, root: result);
}