def get_all_book_stock(): stock = mongo.stocks.find() stock_result = list(stock) if not stock_result: return {'status': 'Error', 'message': 'There is no book stock'}, False return { 'status': 'Success', 'message': utils.result_serializer(stock_result) }, True
def get_loans(): loan = mongo.loans.find() tmp_loan = list(loan) if not tmp_loan: return {'status': 'Error', 'message': 'Loan info not found'}, False return { 'status': 'Error', 'result': utils.result_serializer(tmp_loan) }, True
def get_stock_by_id(book_id): stock = mongo.stocks.find_one({'book_id': book_id}) stock_result = stock if not stock_result: return {'status': 'Error', 'message': 'There is no book stock'}, False return { 'status': 'Success', 'message': utils.result_serializer(stock_result) }, True
def get_all_books(): books = mongo.books.find() all_books = list(books) if not all_books: return {'status': 'Error', 'message': 'Book not found'}, False return { 'status': 'Success', 'result': utils.result_serializer(all_books) }, True
def get_loan_by_id(loan_id): loan = mongo.loans.find({'_id': ObjectId(loan_id)}) tmp_loan = loan if not tmp_loan: return {'status': 'Error', 'message': 'Loan info not found'}, False return { 'status': 'Error', 'result': utils.result_serializer(tmp_loan) }, True
def get_author_by_id(author_id): if not check_author_by_id(author_id): return {'status': 'Error', 'message': 'Author Not Found'}, False author = mongo.authors.find_one({'_id': ObjectId(author_id)}) return { 'status': 'Success', 'result': utils.result_serializer(author) }, True
def get_all_author(): authors = mongo.authors.find() result = list(authors) if not result: return { 'status': 'Error', 'message': 'There is no any author data' }, False return { 'status': 'Success', 'result': utils.result_serializer(result) }, True
def get_book_by_id(book_id): if not check_book_by_id(book_id): return {'status': 'Error', 'message': 'Book not exist'}, False book = mongo.books.find_one({'_id': ObjectId(book_id)}) return {'status': 'Success', 'result': utils.result_serializer(book)}, True
def get_all_users(): users = mongo.users.find() return {"status": "Success", "result": utils.result_serializer(list(users))}, True
def get_user_by_id(user_id): user_is_exist = mongo.users.find_one({"_id": ObjectId(user_id)}) if not user_is_exist: return {"status": "Error", "message": "User not found!"}, False user = mongo.users.find_one({"_id": ObjectId(user_id)}) return {"status": "Success", "result": utils.result_serializer(user)}, True