def get_restaurants(): try: _city = request.args.get('city', default='%', type=str) _restaurant_id = request.args.get('restaurantId', default="%", type=int) _meta = request.args.get('meta', default="NO", type=str) conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT * FROM Restaurant where (SELECT city from Location WHERE Location.id=Restaurant.location_id) LIKE %s AND id LIKE %s ", (_city, _restaurant_id)) rows = cursor.fetchall() if _restaurant_id == "%": rows = convert_restaurant(cursor, rows, meta=_meta) else: rows = convert_restaurant(cursor, rows, reviews=True) print(type(rows)) return send_get_response(rows, "No Restaurant Found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def get_reviews(resId=None, userId=None): _restaurant_id = request.args.get('restaurantId', default="%", type=int) _user_id = request.args.get('userId', default="%", type=int) if resId != None: _restaurant_id = resId if userId != None: _user_id = userId try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT * from Review where restaurant_id LIKE %s AND user_id LIKE %s", (_restaurant_id, _user_id)) reviews = cursor.fetchall() print(reviews) for review in reviews: append_photos(cursor, review) append_restaurant_details(cursor, review) append_user_details(cursor, review) return send_get_response(reviews, "No Review Found ") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: conn.close() cursor.close()
def get_cities(): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM Cities") rows = cursor.fetchall() return send_get_response(rows, "No city found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def get_restaurant_bookings(current_user): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT * FROM Booking where restaurant_id=%s",current_user['id']) rows = cursor.fetchall() return send_get_response(rows,"No Booking Found") except Exception as e: print(e) resp=jsonify("ERROR") resp.status_code=500 return resp finally: conn.close() cursor.close()
def get_user_getrecent_visits(current_user): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT * FROM Booking where user_id=%s ORDER BY date_time_of_booking DESC", current_user['id']) rows = cursor.fetchall()[:5] return send_get_response(rows, "No Booking Found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: conn.close() cursor.close()
def get_highlights(): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute("SELECT * FROM Highlights") rows = cursor.fetchall() ans = [] for row in rows: ans.append(row['name']) return send_get_response(ans, "No Booking Found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def get_restaurants_by_id(id): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) sql = "SELECT * from Restaurant WHERE id=%s" cursor.execute(sql, (id)) rows = cursor.fetchall() convert_restaurant(cursor, rows, reviews=True) return send_get_response(rows, "No Restaurant found for given criteria") except Exception as e: print(e) resp = jsonify("Error") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def get_users(current_user): try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) cursor.execute( "SELECT id,name,email_id,city,admin FROM User where id=%s", current_user['id']) rows = cursor.fetchall() print("sdfsdssssssssss") convert_user(cursor, rows) return send_get_response(rows, "Success") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: conn.close() cursor.close()
def get_restuarant_photos(res_id): try: conn = mysql.connect() cursor = conn.cursor() cursor.execute("SELECT id from Review where restaurant_id=%s", res_id) rows = cursor.fetchall() lis = [] for row in rows: cursor.execute("SELECT url from Photo where review_id=%s", row[0]) rrs = cursor.fetchall() lis = lis + list(rrs) new_list = [i[0] for i in lis] return send_get_response(new_list, "No Photo Found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def get_localities(): city = request.args.get('city') if city == None: resp = jsonify("City Required") resp.status_code = 400 return resp try: conn = mysql.connect() cursor = conn.cursor(pymysql.cursors.DictCursor) # cursor = conn.cursor() cursor.execute("SELECT DISTINCT locality FROM Location WHERE city=%s", city) rows = cursor.fetchall() return send_get_response(rows, "No city found") except Exception as e: print(e) resp = jsonify("ERROR") resp.status_code = 500 return resp finally: cursor.close() conn.close()
def update_restaurant(current_user): try: data=request.json conn=mysql.connect() cursor=conn.cursor() id=current_user['id'] loc_id=cursor.execute("SELECT location_id FROM Restaurant WHERE id=%s",id) update_location(cursor,data[0]['location'],loc_id) update_restaurant_table(cursor,data[0],id) update_days(cursor,data[0]['days'],id) update_slot(cursor,data[0]['slots'],id) conn.commit() return send_get_response(data,"No header") except Exception as e: print(e) resp=jsonify("ERROR") resp.status_code=500 return resp finally: conn.close() cursor.close()