def put(self, relatedBookUuid): # type: ignore data = request.get_json(force=True) if not isinstance(data, dict): abort(400) if 'id' not in data: data['id'] = relatedBookUuid marshmallow_schema_or_errors = convert_dict_to_marshmallow_result( data=data, identifier=relatedBookUuid, identifier_column='related_book_uuid', domain_model=related_book_domain_model, sqlalchemy_model=RelatedBook, schema=related_book_schema, ) if isinstance(marshmallow_schema_or_errors, list): abort(400, marshmallow_schema_or_errors) if marshmallow_schema_or_errors.errors: abort( 400, python_dict_to_json_dict(marshmallow_schema_or_errors.errors)) db.session.add(marshmallow_schema_or_errors.data) db.session.commit() return python_dict_to_json_dict( model_to_dict(marshmallow_schema_or_errors.data, )), 201
def post(self): # type: ignore data = request.get_json(force=True) if not isinstance(data, dict): return abort(400) data['authorId'] = uuid.uuid4() marshmallow_schema_or_errors = convert_dict_to_marshmallow_result( data=data, identifier=data['authorId'], identifier_column='author_id', domain_model=author_domain_model, sqlalchemy_model=Author, schema=author_schema, ) if isinstance(marshmallow_schema_or_errors, list): abort(400, marshmallow_schema_or_errors) if marshmallow_schema_or_errors.errors: abort( 400, python_dict_to_json_dict(marshmallow_schema_or_errors.errors)) db.session.add(marshmallow_schema_or_errors.data) db.session.commit() return python_dict_to_json_dict( model_to_dict(marshmallow_schema_or_errors.data, )), 201
def patch(self, relatedBookUuid): # type: ignore result: Optional[RelatedBook] = RelatedBook.query.filter_by(related_book_uuid=relatedBookUuid)\ .options(noload('*')).first() # noqa: E501 if result is None: abort(404) data = request.get_json(force=True) if not isinstance(data, dict): abort(400) marshmallow_schema_or_errors = convert_dict_to_marshmallow_result( data=json_dict_to_python_dict(model_to_dict(result)), identifier=relatedBookUuid, identifier_column='related_book_uuid', domain_model=related_book_domain_model, sqlalchemy_model=RelatedBook, schema=related_book_schema, patch_data=data, ) if isinstance(marshmallow_schema_or_errors, list): abort(400, marshmallow_schema_or_errors) if marshmallow_schema_or_errors.errors: abort( 400, python_dict_to_json_dict(marshmallow_schema_or_errors.errors)) db.session.add(marshmallow_schema_or_errors.data) db.session.commit() return python_dict_to_json_dict( model_to_dict(marshmallow_schema_or_errors.data, )), 200
def patch(self, authorId): # type: ignore id_validation_errors = author_schema.validate({'author_id': authorId}, session=db.session, partial=True) if id_validation_errors: abort(404) result: Optional[Author] = Author.query.filter_by(author_id=authorId)\ .options(noload('*')).first() # noqa: E501 if result is None: abort(404) data = request.get_json(force=True) if not isinstance(data, dict): abort(400) marshmallow_schema_or_errors = convert_dict_to_marshmallow_result( data=json_dict_to_python_dict(model_to_dict(result)), identifier=authorId, identifier_column='author_id', domain_model=author_domain_model, sqlalchemy_model=Author, schema=author_schema, patch_data=data, ) if isinstance(marshmallow_schema_or_errors, list): abort(400, marshmallow_schema_or_errors) if marshmallow_schema_or_errors.errors: abort( 400, python_dict_to_json_dict(marshmallow_schema_or_errors.errors)) db.session.add(marshmallow_schema_or_errors.data) db.session.commit() return python_dict_to_json_dict( model_to_dict(marshmallow_schema_or_errors.data, )), 200