def create_book(): try: data = request.get_json() book_schema = BookSchema() book = book_schema.load(data) result = book_schema.dump(book.create()) return response_with(resp.SUCCESS_201, value={"book": result}) except Exception as e: return response_with(resp.INVALID_INPUT_422)
def update_book_detail(id): data = request.get_json() get_book = Book.query.get_or_404(id) get_book.title = data['title'] get_book.year = data['year'] db.session.add(get_book) db.session.commit() book_schema = BookSchema() book = book_schema.dump(get_book) return response_with(resp.SUCCESS_200, value={"book": book})
def modify_book_detail(book_id): data = request.get_json() get_book = Book.query.get_or_404(book_id) if data.get("title"): get_book.title = data["title"] if data.get("year"): get_book.year = data["year"] db.session.add(get_book) db.session.commit() book_schema = BookSchema() book = book_schema.dump(get_book) return response_with(resp.SUCCESS_200, value={"book": book})
def modify_book_detail(id): data = request.get_json() get_book = Book.query.get_or_404(id) if data.get('title'): get_book.title = data.get('title') if data.get('year'): get_book.year = data.get('year') db.session.add(get_book) db.session.commit() book_schema = BookSchema() book = book_schema.dump(get_book) return response_with(resp.SUCCESS_200, value={'book': book})
def get_book_detail(id): fetched = Book.query.get_or_404(id) book_schema = BookSchema() books = book_schema.dump(fetched) return response_with(resp.SUCCESS_200, value={"books": books})
def get_book_list(): fetched = Book.query.all() book_schema = BookSchema(many=True, only=['author_id', 'title', 'year']) books = book_schema.dump(fetched) return response_with(resp.SUCCESS_200, value={"books": books})
def get_book_list(): fetched = Book.query.all() book_schema = BookSchema(many=True) result = book_schema.dump(fetched) return response_with(resp.SUCCESS_200, value={"books": result})