def get(self): """ Get all meetups """ cur.execute("SELECT * FROM meetups") meetups = cur.fetchall() all_meetups = [] for item in meetups: format_meetup = { 'meetup_id': item[0], 'location': item[1], 'images': item[2], 'title': item[3], 'happeningOn': item[4], 'tags': item[5], 'time_added': str(item[6]) } all_meetups.append(format_meetup) if len(all_meetups) < 1: res = { "status": 404, "message": "There are no meetups at the moment" }, 404 return res return {"status": 200, "data": all_meetups}, 200
def get(self): """ Get all products """ current_user = get_jwt_identity() if current_user is None: msg = 'Please login to access to access this resource' return {"status": "Failed!", "message": msg}, 400 store_id = get_store_id(get_jwt_identity()) cur.execute( "SELECT * FROM products WHERE store_id={};".format(store_id)) products = cur.fetchall() all_products = [] for p in products: format_p = { 'product_id': p[0], 'name': p[2], 'inventory': p[3], 'price': p[4], 'category': p[5], 'added_at': p[6] } all_products.append(format_p) if len(all_products) < 1: res = { "status": "Failed!", "message": "There are no products at the moment" }, 404 return res return {"status": "Success!", "products": all_products}, 200
def get(self, id): """ Get all questions for a specific meetup """ cur.execute("SELECT * FROM questions WHERE meetup_id={};".format(id)) questions = cur.fetchall() mtup = get_meetup_by_id(id) all_questions = [] for item in questions: format_quiz = { 'question_id': item[0], 'username': item[1], 'meetup_id': item[2], 'votes': item[3], 'title': item[4], 'body': item[5], 'time_added': str(item[6]) } all_questions.append(format_quiz) if not mtup or mtup[0] != id: msg = 'Meetup with that id does not exist' return {"Status": 404, "Message": msg}, 404 if len(all_questions) < 1: res = { "Status": 404, "Message": "There are no Questions at the moment" }, 404 return res return {"Status": 200, "data": all_questions}, 200
def cart_helper(email): """ Method to get cart that belongs to a specific user """ user = get_user_by_email(email) cur.execute("SELECT * FROM carts WHERE seller_id={};".format(user[0])) carts = cur.fetchall() return carts
def get(self): """ Get all get categories """ current_user = get_jwt_identity() if current_user is None: msg = 'Please login to access to access this resource' return {"status": "Failed!", "message": msg}, 400 store_id = get_store_id(get_jwt_identity()) cur.execute( "SELECT * FROM categories WHERE store_id='{}';".format(store_id)) categories = cur.fetchall() if len(categories) < 1: return {"message": "There are no categories at this time"}, 404 all_categories = [] for c in categories: format_cat = {"id": c[0], "name": c[2], "Added_at": c[3]} all_categories.append(format_cat) return {"status": "Success!", "categories": all_categories}, 200
def get(self, id): """ Get a single question """ cur.execute("SELECT * FROM questions WHERE id={};".format(id)) quests = cur.fetchall() mtup = get_meetup_by_id(id) qsn = get_question_by_id(id) if not qsn: msg = 'Question with that id does not exist' return {"Status": 404, "Message": msg}, 404 for item in quests: format_quest = { 'question_id': item[0], 'user_id': item[1], 'meetup_id': item[2], 'votes': item[3], 'title': item[4], 'body': item[5], 'time_added': str(item[6]) } if not mtup or mtup[0] != id: msg = 'Meetup with that id does not exist' return {"status": 200, "question": format_quest}, 200