Exemple #1
0
    def put(self, book_id, author, title, date, genre):
        '''Update a book by book id'''
        cur_book = BookModel.find_by_id(book_id)

        if not cur_book:
            return {'message' : 'book with id {} is not found.'.format(book_id)}, 404

        new_author = AuthorModel.search_and_add_author(author)
        new_genre = GenreModel.search_and_add_genre(genre)
        new_date = DateRead.read_date(date)

        cur_book = BookModel.update_book(book_id, title, new_author, new_date, new_genre)
        return cur_book.json(), 200
Exemple #2
0
    def post(self, title, author, date, genre):
        '''Add a new book'''
        cur_author = AuthorModel.search_and_add_author(author)

        cur_genre = GenreModel.search_and_add_genre(genre)

        release_date = DateRead.read_date(date)

        #create the new book, add into db
        new_book = BookModel(title, cur_author.id, release_date, cur_genre)
        new_book.save_to_db()

        if not new_book:
            return {"message" : "add book error"}, 403
        return new_book.json(), 201