def insertBookStore(): params = book_store_schema.load(get_param()) book_store = BookStore(params['storeName'], params['cashBalance'], params['openingHours']) book_store.insert() return { 'message': 'Insert done!' }
def user_buy_book(): params = get_param() book_store_name = params.get('book_store_name', None) book_name = params.get('book_name', None) user_id = params.get('id', None) if book_store_name is None or book_name is None or user_id is None: return { 'result': 'Error!' } book_store = BookStore.get(book_store_name) if book_store is None: return { 'result': 'Book Store is not found!' } price = Book.get_price_by_store_name_book_name(book_store.storeName, book_name) if price is None: return { 'result': 'Book is not found!' } user = User.get_by_id(user_id) if user is None: return { 'result': 'User is not found!' } user.cashBalance -= price[0] book_store.cashBalance += price[0] user.update() book_store.update() purchase = PurchaseHistory(user_id, book_name, book_store_name, price[0], "today") purchase.insert() return { 'result': purchage_history_schema.dump(purchase) }
def insertBook(): params = get_param() store = BookStore.get(params['storeName']) book = Book(store.id, params["bookName"], params["price"]) book.insert() return { "message": "Insert done!" }
def getAllBookStores(): book_stores = BookStore.get_all() book_store_list = [] for book_store in book_stores: book_store_list.append(book_store_schema.dump(book_store)) return { 'result': book_store_list }
def getBookStoreByTime(): time = request.args.get('time', type=str) book_stores = BookStore.get_all_by_time(time) book_store_list = [] for book_store in book_stores: book_store_list.append(book_store_schema.dump(book_store)) return { 'result': book_store_list }
def get_by_key_word(): key_word = request.args.get('keyword', type=str) stores = BookStore.get_all_by_key_word(key_word) store_list = [] for store in stores: store_list.append(book_store_schema.dump(store)) return { "result": store_list }
def get_by_book_count(): count = request.args.get('count', type=int) is_greater = request.args.get('greater', tpye=bool) stores = BookStore.get_all_by_count(count, is_greater) store_list = [] for store in stores: store_list.append(book_store_schema.dump(store)) return { "result": store_list }
def get_by_book_price_count(): price = request.args.get('price', type=float) count = request.args.get('count', type=int) is_greater = request.args.get('greater', type=bool) stores = BookStore.get_all_by_price_and_count(price, count, is_greater) store_list = [] for store in stores: store_list.append(book_store_schema.dump(store)) return { "result": store_list }
def update_book_store_by_name(): params = get_param() query = BookStore.get(params['oldname']) if query is None: return { 'result': 'book store is not found.' } query.storeName = params['newname'] query.update() store = book_store_schema.dump(query) return { "result": store }