def post(self): usr = current_user bookings = api.payload['bookings'] q1 = """ UPDATE FlightBooking SET is_paid=TRUE WHERE user_id={} AND flight_id ={} AND seat_no={} """ try: for booking in bookings: Query(query=q1.format(usr.user_id, booking['flight_id'], booking['seat_no'])) return {"message": "Payment successful"}, 200 except Exception as e: return {"message": "Payment failed"}, 400
def get(self): query = """ SELECT r.hotel_id, r.room_no, CAST(r.cost AS CHAR) AS cost FROM Room r WHERE r.hotel_id = {} AND CONCAT_WS(r.hotel_id, r.room_no) NOT IN ( SELECT DISTINCT CONCAT_WS(hb.hotel_id, hb.room_no) FROM HotelBooking hb WHERE GREATEST(DATEDIFF(LEAST('{}', hb.end_date), GREATEST('{}', hb.start_date)), 0) > 0 ) """ hotel_id = request.args.get("hotel_id") start_date = request.args.get("start_date") end_date = request.args.get("end_date") q = Query(query) return { "rooms": q.getAll(hotel_id, end_date, start_date) }
def get(self): city = request.args.get('city') start_date = request.args.get('start_date') end_date = request.args.get('end_date') query = """ SELECT h.hotel_id, h.hotel_name, a.*, CAST(MIN(r.cost) AS CHAR) AS min_cost FROM Hotel h JOIN Room r ON r.hotel_id = h.hotel_id JOIN Address a ON a.address_id = h.address_id WHERE a.city = '{}' AND CONCAT_WS(h.hotel_id, r.room_no) NOT IN ( SELECT DISTINCT CONCAT_WS(hb.hotel_id, hb.room_no) FROM HotelBooking hb WHERE GREATEST(DATEDIFF(LEAST('{}', hb.end_date), GREATEST('{}', hb.start_date)), 0) > 0 ) GROUP BY h.hotel_id; """ res = Query(query=query) return { "hotels": [a for a in res.getAll(city, end_date, start_date)] }
def get_user_from_email(email): q = Query("SELECT * FROM User WHERE email = '{}'", model=User) usr = q.getOne(email) assert usr is not None return usr
def load_user(user_id): q = Query("SELECT * FROM User WHERE user_id = {}", model=User) usr = q.getOne(user_id) return usr