def store_platforms(): try: platform_list = dbm.fetch_platforms() return jsonify(platform_list) except Exception as e: print e return internal_server_error()
def update_announcement(aid): try: if request.json: for key in announcement_keys: if key not in request.json: return jsonify({ "error": "Paramenter {0} missing in request".format(key) }) if int(request.json['platformid']) > 0: result = dbm.edit_platform_announcement( request.json['a_img'], request.json['a_title'], request.json['active'], request.json['aid'], request.json['platformid']) else: result = dbm.edit_store_announcement(request.json['a_img'], request.json['a_title'], request.json['active'], request.json['aid']) return jsonify({'aid': result}) else: return bad_request() except Exception as e: print e.message return internal_server_error()
def user_payment(userid): try: if request.method == 'GET': payment_method = dbm.fetch_user_payment_methods(userid) if payment_method: return jsonify(payment_method) return not_found() elif request.method == 'POST': if request.json: payment_keys = post_payment_keys payment_keys.append('ppreferred') for key in payment_keys: if key not in request.json: return jsonify( {"Errors": "Missing {0} in request.".format(key)}), 400 errors = validate_payment(request.json) if errors: return jsonify({'Errors': errors}), 400 billing_addressid = dbm.fetch_user_preferences( userid)['billing_address']['aid'] if billing_addressid: pid = dbm.create_user_payment_method( userid, request.json, billing_addressid) return jsonify({'payment_methodid': pid}), 201 else: return jsonify({ 'error': 'Preferred Billing Address Not Found For User {0}'. format(userid) }), 400 return bad_request() except Exception as e: print e.message return internal_server_error()
def get_product_alt_imgs(productid): try: imgs = dbm.fetch_product_alt_img(productid) return jsonify(imgs) except Exception as e: print e return internal_server_error()
def related_products(productid): try: results = dbm.fetch_related_products(productid) return jsonify(results) except Exception as e: print e return internal_server_error()
def store_top(): try: top = dbm.fetch_home_top() return jsonify(top) except Exception as e: print e return internal_server_error()
def user(userid): try: if request.method == 'GET': cg_user = dbm.fetch_user_info(userid=userid) if cg_user: return jsonify(cg_user) return not_found() elif request.method == 'PUT': if request.json: # Verify request json contains needed parameters if not ('uname' or 'ufirstname' or 'ulastname' or 'uemail' or 'uphone' or 'udob' in request.json): return missing_parameters_error() # Verify that parameters are valid errors = validate_update_account_data(request.json) if errors: return jsonify({'Errors': errors}), 400 # Update user account: if dbm.update_user_account(userid, request.json): response = jsonify(request.json) response.status_code = 201 return response return not_found() else: return bad_request() except Exception as e: print e return internal_server_error()
def activate_genre(genreid): try: result = dbm.activate_genre(genreid) return jsonify({"mesagge": result}) except Exception as e: print e.message return internal_server_error()
def platform_top(platformid): try: top = dbm.fetch_platform_top(platformid) return jsonify(top) except Exception as e: print e return internal_server_error()
def user_address(userid): try: if request.method == 'GET': address = dbm.fetch_user_address(userid) if address: return jsonify(address) return not_found() elif request.method == 'POST': if request.json: address_keys = post_address_keys address_keys.append('apreferred') address_keys.append('atype') for key in address_keys: if key not in request.json: return missing_parameters_error() errors = validate_address(request.json) if errors: return jsonify({'Errors': errors}), 400 if request.json[ 'atype'] == 'billing' and 'pid' not in request.json: return jsonify({'Errors': "Missing Payment Method."}), 400 new_address_id = dbm.create_user_address(userid, request.json) return jsonify({'aid': new_address_id}), 201 else: return missing_parameters_error() except Exception as e: print e.message return internal_server_error()
def update_order_status(order_statusid, orderid): try: result = dbm.change_order_status(order_statusid, orderid) return jsonify({"mesagge": result}) except Exception as e: print e.message return internal_server_error()
def update_payment(userid, payment_methodid): try: if request.method == 'PUT': if request.json: payment_keys = post_payment_keys payment_keys.append('ppreferred') for key in payment_keys: if key not in request.json: return missing_parameters_error() errors = validate_payment(request.json) if errors: return jsonify({'Errors': errors}), 400 billing_addressid = dbm.fetch_user_preferences( userid)['billing_address']['aid'] if billing_addressid: pid = dbm.update_payment_method(userid, payment_methodid, request.json, billing_addressid) return jsonify({'payment_methodid': pid}), 201 else: return jsonify({ 'Error': 'Preferred Billing Address Not Found For User {0}'. format(userid) }), 400 return bad_request() elif request.method == 'DELETE': result = dbm.deactivate_user_payment_method( userid, payment_methodid) if result: return jsonify(result) return bad_request() except Exception as e: print e.message return internal_server_error()
def user_preferences(userid): try: if request.method == 'GET': preferences = dbm.fetch_user_preferences(userid) if preferences: return jsonify(preferences) return not_found() elif request.method == 'PUT': if ('shipping_addressid' or 'billing_addressid' or 'cid') not in request.json: return missing_parameters_error() errors = validate_user_preferences(request.json, userid) if errors: return jsonify({'errors': errors}), 400 if 'shipping_addressid' in request.json: dbm.update_user_preferred_shipping( request.json['shipping_addressid'], userid) if 'billing_addressid' in request.json: dbm.update_user_preferred_billing( request.json['billing_addressid'], userid) if 'cid' in request.json: dbm.update_user_preferred_payment(request.json['cid'], userid) preferences = dbm.fetch_user_preferences(userid) if preferences: return jsonify(preferences) return bad_request() except Exception as e: print e.message return internal_server_error()
def deactivate_product(productid): try: result = dbm.deactivate_product(productid) return jsonify({"mesagge": result}) except Exception as e: print e.message return internal_server_error()
def deactivate_platform_admi(platformid): try: result = dbm.deactivate_platform(platformid) return jsonify({"mesagge": result}) except Exception as e: print e.message return internal_server_error()
def user_wish_list(userid): try: if request.method == 'GET': wish_list = dbm.fetch_user_wish_list(userid=userid) return jsonify(wish_list) except: return internal_server_error()
def delete_from_user_wish_list(userid, productid): try: if request.method == 'DELETE': in_wish_list = dbm.wish_list_contains( productid=productid, userid=userid)['product_in_wishlist'] if in_wish_list: dbm.remove_from_wish_list(productid=productid, userid=userid) wish_list = dbm.fetch_user_wish_list(userid=userid) return jsonify(wish_list) else: not_found() elif request.method == 'POST': in_wish_list = dbm.wish_list_contains( productid=productid, userid=userid)['product_in_wishlist'] if not in_wish_list: dbm.add_product_to_user_wishlist(productid=productid, userid=userid) wish_list = dbm.fetch_user_wish_list(userid=userid) return jsonify(wish_list) else: return jsonify({ 'error': 'Product {0} is already in user {1} wish list.'.format( productid, userid) }), 400 except Exception as e: print e return internal_server_error()
def home_announcements(): try: # Global Store (Home) carousel announcements home_announcements_list = dbm.fetch_store_announcements() return jsonify(home_announcements_list) except Exception as e: print e return internal_server_error()
def user_shipping_address(userid): try: address = dbm.fetch_user_shipping_address(userid) if address: return jsonify(address) return not_found() except Exception as e: print e return internal_server_error()
def get_genre(): try: genre = dbm.fetch_all_genre() if genre: return jsonify(genre) return not_found() except Exception as e: print e return internal_server_error()
def get_categories(): try: categories = dbm.fetch_all_categories() if categories: return jsonify(categories) return not_found() except Exception as e: print e return internal_server_error()
def get_ratings(): try: rating = dbm.fetch_esrb_ratings() if rating: return jsonify(rating) return not_found() except Exception as e: print e return internal_server_error()
def shipment_fees(): try: result = dbm.fetch_shipment_fees() if result: return jsonify(result) return not_found() except Exception as e: print e return internal_server_error()
def get_users(): try: users = dbm.fetch_users() if users: return jsonify(users) return not_found() except Exception as e: print e return internal_server_error()
def get_orders(): try: orders = dbm.fetch_all_orders() if orders: return jsonify(orders) return not_found() except Exception as e: print e return internal_server_error()
def get_platforms(): try: platforms = dbm.fetch_all_platforms() if platforms: return jsonify(platforms) return not_found() except Exception as e: print e return internal_server_error()
def get_platform(platformid): try: for p in platform_list: if p['platformid'] == platformid: return jsonify(p) return not_found() except Exception as e: print e return internal_server_error()
def get_all_status(): try: status = dbm.fetch_all_status() if status: return jsonify(status) return not_found() except Exception as e: print e return internal_server_error()
def get_products(): try: products = dbm.fetch_all_products() if products: return jsonify(products) return not_found() except Exception as e: print e return internal_server_error()
def get_product(productid): try: product = dbm.fetch_product(productid) if product: return jsonify(product) return not_found() except Exception as e: print e return internal_server_error()