def post(self, type_): """Update Non Collection class item.""" if get_authentication(): if request.authorization is None: return failed_authentication() else: try: auth = check_authorization(request, get_session()) if auth is False: return failed_authentication() except Exception as e: status_code, message = e.get_HTTP() return set_response_headers(jsonify(message), status_code=status_code) if checkEndpoint("POST", type_): object_ = json.loads(request.data.decode('utf-8')) if type_ in get_doc().parsed_classes and type_+"Collection" not in get_doc().collections: obj_type = getType(type_, "POST") if validObject(object_): if object_["@type"] == obj_type: # try: crud.update_single(object_=object_, session=get_session(), api_name=get_api_name()) headers_ = [{"Location": get_hydrus_server_url()+get_api_name()+"/"+type_+"/"}] response = {"message": "Object successfully updated"} return set_response_headers(jsonify(response), headers=headers_) # except Exception as e: # status_code, message = e.get_HTTP() # return set_response_headers(jsonify(message), status_code=status_code) return set_response_headers(jsonify({400: "Data is not valid"}), status_code=400) abort(405)
def on_post(self, req, resp, type_: str): """ Method executed for POST requests. Used to update a non-collection class. :param type_ - Item type """ if get_authentication(resp): if req.auth is None: return failed_authentication(resp) else: try: auth = check_authorization(req, get_session(resp)) if auth is False: return failed_authentication(resp) except Exception as e: status_code, message = e.get_HTTP() # type: ignore resp.media = message return set_response_headers(resp, status_code=status_code) endpoint_ = checkEndpoint(resp, "POST", type_) if endpoint_['method']: object_ = req.media if type_ in get_doc( resp ).parsed_classes and type_ + "Collection" not in get_doc( resp).collections: obj_type = getType(resp, type_, "POST") if validObject(object_): if object_["@type"] == obj_type: try: crud.update_single(object_=object_, session=get_session(resp), api_name=get_api_name(resp)) headers_ = [{ "Location": get_hydrus_server_url(resp) + get_api_name(resp) + "/" + type_ + "/" }] response = { "message": "Object successfully updated" } resp.media = response return set_response_headers(resp, headers=headers_[0]) except Exception as e: status_code, message = e.get_HTTP() resp.media = message return set_response_headers( resp, status_code=status_code) return set_response_headers(resp, status_code=falcon.HTTP_400)
def post(self, path: str) -> Response: """ Method executed for POST requests. Used to update a non-collection class. :param path - Path for Item type ( Specified in APIDoc @id) """ auth_response = check_authentication_response() if isinstance(auth_response, Response): return auth_response endpoint_ = checkEndpoint("POST", path) if endpoint_['method']: object_ = json.loads(request.data.decode('utf-8')) if path in get_doc().parsed_classes and "{}Collection".format(path) not in get_doc( ).collections: obj_type = getType(path, "POST") if check_read_only_props(obj_type, object_): if object_["@type"] == obj_type and check_required_props( obj_type, object_) and validObject(object_): try: crud.update_single( object_=object_, session=get_session(), api_name=get_api_name(), path=path) headers_ = [ {"Location": "{}/{}/".format( get_hydrus_server_url(), get_api_name(), path)}] response = { "message": "Object successfully updated"} return set_response_headers( jsonify(response), headers=headers_) except (ClassNotFound, InstanceNotFound, InstanceExists, PropertyNotFound) as e: status_code, message = e.get_HTTP() return set_response_headers( jsonify(message), status_code=status_code) return set_response_headers( jsonify({400: "Data is not valid"}), status_code=400) else: abort(405) abort(endpoint_['status'])
def post(self, type_: str) -> Response: """ Method executed for POST requests. Used to update a non-collection class. :param type_ - Item type """ auth_response = check_authentication_response() if type(auth_response) == Response: return auth_response endpoint_ = checkEndpoint("POST", type_) if endpoint_['method']: object_ = json.loads(request.data.decode('utf-8')) if type_ in get_doc( ).parsed_classes and type_ + "Collection" not in get_doc( ).collections: obj_type = getType(type_, "POST") if validObject(object_): if object_["@type"] == obj_type: try: crud.update_single(object_=object_, session=get_session(), api_name=get_api_name()) headers_ = [{ "Location": get_hydrus_server_url() + get_api_name() + "/" + type_ + "/" }] response = { "message": "Object successfully updated" } return set_response_headers(jsonify(response), headers=headers_) except (ClassNotFound, InstanceNotFound, InstanceExists, PropertyNotFound) as e: status_code, message = e.get_HTTP() return set_response_headers( jsonify(message), status_code=status_code) return set_response_headers(jsonify({400: "Data is not valid"}), status_code=400) abort(endpoint_['status'])