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 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 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 get(self, authorId): # type: ignore result: Optional[Author] = Author.query.filter_by( author_id=authorId).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self, bookGenreId): # type: ignore result: Optional[BookGenre] = BookGenre.query.filter_by( book_genre_id=bookGenreId).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self, reviewId): # type: ignore result: Optional[Review] = Review.query.filter_by( review_id=reviewId).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self): query = Book.query param_book_id = request.args.getlist('book_id') if param_book_id: query = query.filter(Book.book_id.in_(param_book_id)) param_name = request.args.getlist('name') if param_name: query = query.filter(Book.name.in_(param_name)) param_rating = request.args.getlist('rating') if param_rating: query = query.filter(Book.rating.in_(param_rating)) param_author_id = request.args.getlist('author_id') if param_author_id: query = query.filter(Book.author_id.in_(param_author_id)) param_collaborator_id = request.args.getlist('collaborator_id') if param_collaborator_id: query = query.filter( Book.collaborator_id.in_(param_collaborator_id)) param_published = request.args.getlist('published') if param_published: query = query.filter(Book.published.in_(param_published)) param_created = request.args.getlist('created') if param_created: query = query.filter(Book.created.in_(param_created)) param_updated = request.args.getlist('updated') if param_updated: query = query.filter(Book.updated.in_(param_updated)) result = query.all() return python_dict_to_json_dict( {"data": [model_to_dict(r) for r in result]})
def get(self, relatedBookUuid): # type: ignore result: Optional[RelatedBook] = RelatedBook.query.filter_by( related_book_uuid=relatedBookUuid).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self): query = Book.query param_book_id = request.args.get('book_id') if param_book_id: query = query.filter_by(book_id=param_book_id) param_name = request.args.get('name') if param_name: query = query.filter_by(name=param_name) param_rating = request.args.get('rating') if param_rating: query = query.filter_by(rating=param_rating) param_author_id = request.args.get('author_id') if param_author_id: query = query.filter_by(author_id=param_author_id) param_collaborator_id = request.args.get('collaborator_id') if param_collaborator_id: query = query.filter_by(collaborator_id=param_collaborator_id) param_published = request.args.get('published') if param_published: query = query.filter_by(published=param_published) param_created = request.args.get('created') if param_created: query = query.filter_by(created=param_created) param_updated = request.args.get('updated') if param_updated: query = query.filter_by(updated=param_updated) result = query.all() return python_dict_to_json_dict({"data": [model_to_dict(r) for r in result]})
def get(self): query = Genre.query param_genre_id = request.args.get('genre_id') if param_genre_id: query = query.filter_by(genre_id=param_genre_id) param_title = request.args.get('title') if param_title: query = query.filter_by(title=param_title) result = query.all() return python_dict_to_json_dict({"data": [model_to_dict(r) for r in result]})
def get(self, bookGenreId): # type: ignore id_validation_errors = book_genre_schema.validate( {'book_genre_id': bookGenreId}, session=db.session, partial=True) if id_validation_errors: abort(404) result: Optional[BookGenre] = BookGenre.query.filter_by( book_genre_id=bookGenreId).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self): query = BookGenre.query param_book_genre_id = request.args.get('book_genre_id') if param_book_genre_id: query = query.filter_by(book_genre_id=param_book_genre_id) param_book_id = request.args.get('book_id') if param_book_id: query = query.filter_by(book_id=param_book_id) param_genre_id = request.args.get('genre_id') if param_genre_id: query = query.filter_by(genre_id=param_genre_id) result = query.all() return python_dict_to_json_dict({"data": [model_to_dict(r) for r in result]})
def get(self): query = RelatedBook.query param_related_book_uuid = request.args.getlist('related_book_uuid') if param_related_book_uuid: query = query.filter(RelatedBook.related_book_uuid.in_(param_related_book_uuid)) param_book1_id = request.args.getlist('book1_id') if param_book1_id: query = query.filter(RelatedBook.book1_id.in_(param_book1_id)) param_book2_id = request.args.getlist('book2_id') if param_book2_id: query = query.filter(RelatedBook.book2_id.in_(param_book2_id)) result = query.all() return python_dict_to_json_dict({"data": [model_to_dict(r) for r in result]})
def get(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).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
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
def get(self, reviewId): # type: ignore id_validation_errors = review_schema.validate({'review_id': reviewId}, session=db.session, partial=True) if id_validation_errors: abort(404) result: Optional[Review] = Review.query.filter_by( review_id=reviewId).first() # noqa: E501 if result is None: abort(404) response = python_dict_to_json_dict(model_to_dict(result, )), 200 return response
def get(self): query = Review.query param_review_id = request.args.get('review_id') if param_review_id: query = query.filter_by(review_id=param_review_id) param_text = request.args.get('text') if param_text: query = query.filter_by(text=param_text) param_book_id = request.args.get('book_id') if param_book_id: query = query.filter_by(book_id=param_book_id) result = query.all() return python_dict_to_json_dict( {"data": [model_to_dict(r) for r in result]})
def get(self): query = Review.query param_review_id = request.args.getlist('review_id') if param_review_id: query = query.filter(Review.review_id.in_(param_review_id)) param_text = request.args.getlist('text') if param_text: query = query.filter(Review.text.in_(param_text)) param_book_id = request.args.getlist('book_id') if param_book_id: query = query.filter(Review.book_id.in_(param_book_id)) result = query.all() return python_dict_to_json_dict( {"data": [model_to_dict(r) for r in result]})
def get(self): query = Author.query param_author_id = request.args.get('author_id') if param_author_id: query = query.filter_by(author_id=param_author_id) param_name = request.args.get('name') if param_name: query = query.filter_by(name=param_name) param_favourite_author_id = request.args.get('favourite_author_id') if param_favourite_author_id: query = query.filter_by(favourite_author_id=param_favourite_author_id) param_hated_author_id = request.args.get('hated_author_id') if param_hated_author_id: query = query.filter_by(hated_author_id=param_hated_author_id) result = query.all() return python_dict_to_json_dict({"data": [model_to_dict(r) for r in result]})
def get(self): query = Author.query param_author_id = request.args.getlist('author_id') if param_author_id: query = query.filter(Author.author_id.in_(param_author_id)) param_name = request.args.getlist('name') if param_name: query = query.filter(Author.name.in_(param_name)) param_favourite_author_id = request.args.getlist('favourite_author_id') if param_favourite_author_id: query = query.filter( Author.favourite_author_id.in_(param_favourite_author_id)) param_hated_author_id = request.args.getlist('hated_author_id') if param_hated_author_id: query = query.filter( Author.hated_author_id.in_(param_hated_author_id)) result = query.all() return python_dict_to_json_dict( {"data": [model_to_dict(r) for r in result]})
def get(self, bookId): # type: ignore result: Optional[Book] = Book \ .query \ .options( joinedload('genre') ) \ .filter_by( book_id=bookId) \ .first() # noqa: E501 if result is None: abort(404) result_dict = python_dict_to_json_dict(model_to_dict( sqlalchemy_model=result, paths=[ 'genre', ], )) return result_dict
def get(self, authorId): # type: ignore result: Optional[Author] = Author \ .query \ .options( joinedload('books') ) \ .filter_by( author_id=authorId) \ .first() # noqa: E501 if result is None: abort(404) result_dict = python_dict_to_json_dict(model_to_dict( sqlalchemy_model=result, paths=[ 'books', ], )) return result_dict