def get(self): """Search edge in collections of kind edge from DB.""" args = pag_collections_arguments.parse_args(request) try: try: page = args.get('page') query = args.get('query') or '[]' per_page = args.get('per_page') collections = args.get('collections').split(',') data = json.loads(query) except JSONDecodeError: raise gmap_exc.SearchException('Parameter query is invalid') else: res = facade.search_collections(collections, data, page, per_page) return res, 200 except gmap_exc.CollectionNotExist as err: api.abort(404, errors=err.message) except ValidationError as error: res = validate(error) api.abort(400, errors=res)
def create_graph(): """Create graph in DB.""" try: data = json.loads(request.data) facade.create_graph(data) return {}, 200 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except Exception as err: return str(err), 500
def create_collection(): """Create collection of kind document in DB.""" try: data = json.loads(request.data) facade.create_collection_document(data) return {}, 200 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except gmap_exc.CollectionNotExist as err: return err.message, 404 except Exception as err: return str(err), 500
def patch_document(collection, key): """Partial update document.""" try: data = json.loads(request.data) res = facade.patch_document(collection, key, data) return res, 200 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except gmap_exc.CollectionNotExist as err: return err.message, 404 except gmap_exc.DocumentNotExist as err: return err.message, 404 except Exception as err: return str(err), 500
def create_document(collection): """Insert document in DB.""" try: data = json.loads(request.data) res = facade.create_document(collection, data) return res, 200 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except gmap_exc.CollectionNotExist as err: return err.message, 404 except gmap_exc.DocumentException as err: return err.message, 400 except Exception as err: return str(err), 500
def update_edge(edge, key): """Update edge.""" try: data = json.loads(request.data) res = facade.update_edge(edge, key, data) return res, 200 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except gmap_exc.EdgeNotExist as err: return err.message, 404 except gmap_exc.DocumentNotExist as err: return err.message, 404 except Exception as err: return str(err), 500
def edges(edge): """Insert edge in DB.""" try: data = json.loads(request.data) res = facade.create_edge(edge, data) return res, 200 except gmap_exc.EdgeNotExist as err: return err.message, 404 except JSONDecodeError as err: return str(err), 400 except ValidationError as error: res = validate(error) return res, 400 except gmap_exc.DocumentException as err: return err.message, 400 except Exception as err: return str(err), 500
def get(self, edge): """Search documents from collection.""" args = pagination_arguments.parse_args(request) try: try: page = args.get('page') query = args.get('query') or '[]' per_page = args.get('per_page') data = json.loads(query) except JSONDecodeError: api.abort(400, errors='Parameter query is invalid') else: res = facade.search(edge, data, page, per_page) return res, 200 except gmap_exc.CollectionNotExist as err: api.abort(404, errors=err.message) except ValidationError as error: res = validate(error) api.abort(400, errors=res)