def get_copy(book_copy_id):
     """
     Method to get a copy of a book by copy id.
     :param book_copy_id: Integer of record for a copy.
     :return: Dictionary of book copy.
     """
     if BookCopyDao.contains(book_copy_id):
         return BookCopyDao.get_book_copy(book_copy_id)
     else:
         abort(404, 'Resource not found: book_copy_id')
 def get_copies(book_id):
     """
     Method to get all copies of a book.
     :param book_id: Integer record of a book.
     :return: List of dictionaries of copies.
     """
     if BookDao.contains(book_id):
         return BookCopyDao.get_book_copies(book_id)
     else:
         abort(404, 'Resource not found: book_id')
Esempio n. 3
0
    def delete_checkout(checkout_id):

        print('Delete checkout')

        a_checkout = Checkout.query.filter_by(checkout_id=checkout_id).delete()
        book_copy_id = a_checkout.book_copy_id
        book_copy = BookCopyDao.get_book_copy(book_copy_id)
        book_copy.is_checked_out = False
        db.session.commit()
        return a_checkout, 204
Esempio n. 4
0
    def update(checkout_id, checkout_info_dict):

        print('Updating checkout')
        a_checkout = Checkout.query.get(checkout_id)
        book_copy_id = a_checkout.book_copy_id
        book_copy = BookCopyDao.get_book_copy(book_copy_id)
        book_copy.is_checked_out = False
        a_checkout.update(**checkout_info_dict)
        db.session.commit()
        return a_checkout.to_dict()
 def create_copy(book_id):
     """
     Method to create a new copy for a book.
     :param book_id: Book record to create a copy for.
     :return: Dictionary of created Copy.
     """
     print('BookCopyChecker.create_copy()')
     if BookDao.contains(book_id):
         return BookCopyDao.create(book_id)
     else:
         abort(404, 'Resource not found: book_id')
Esempio n. 6
0
    def create_new_checkout(checkout_dict):

        new_checkout = Checkout(**checkout_dict)
        book_copy_id = new_checkout.book_copy_id
        book_copy = BookCopyDao.get_book_copy(book_copy_id)
        book_copy.is_checked_out = True

        db.session.add(new_checkout)
        db.session.commit()
        print('checkout created')

        return new_checkout.checkout_id
def create_checkout(json_checkout_info):
    book_copy_id = json_checkout_info['book_copy_id']
    if BookCopyDao.get_book_copy(book_copy_id).is_checked_out is True:
        return abort(400, 'book already checked out')

    user_id = json_checkout_info['user_id']
    book_id = json_checkout_info['book_id']
    checkout_date = json_checkout_info['checkout_date']
    due_date = json_checkout_info['due_date']
    return_date = json_checkout_info['return_date']

    checkout_dict = clean_checkout(user_id, book_id, book_copy_id,
                                   checkout_date, due_date, return_date)
    return CheckoutDao.create_new_checkout(checkout_dict)