def update_event(): jsn = json.loads(request.data) id = jsn.get('id', '') title = jsn.get('title', '') date_event = jsn.get('date_event', '') time_event = jsn.get('time_event', '') spcall('updatecater', (id, title, date_event, time_event), True) return jsonify({"status": "OK"})
def update_catering(): jsn = json.loads(request.data) c_id = jsn.get('c_id', '') c_name = jsn.get('c_name', '') c_email_address = jsn.get('c_email_address', '') c_description = jsn.get('c_description', '') c_location = jsn.get('c_location', '') c_pricing = jsn.get('c_pricing', '') c_categories = jsn.get('c_categories', '') spcall('updatecater', (c_id, c_name, c_email_address, c_description, c_location, c_pricing, c_categories), True) return jsonify({"status": "OK"})
def store_note(): jsn = json.loads(request.data) res = spcall('newnote', (jsn['event_id'], jsn['title'], jsn['note'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]}), 200
def update_user(): jsn = json.loads(request.data) user_id = jsn.get('user_id', '') email_address = jsn.get('email_address', '') fname = jsn.get('fname', '') lname = jsn.get('lname', '') password = jsn.get('password', '') address = jsn.get('address', '') birthdate = jsn.get('birthdate', '') age = jsn.get('age', '') spcall('updateuser', (user_id, email_address, fname, lname, password, address, birthdate, age), True) return jsonify({"status": "OK"})
def update_venue(): jsn = json.loads(request.data) v_id = jsn.get('v_id', '') v_name = jsn.get('v_name', '') v_email_address = jsn.get('v_email_address', '') v_description = jsn.get('v_description', '') v_location = jsn.get('v_location', '') v_capacity = jsn.get('v_capacity', '') v_pricing = jsn.get('v_pricing', '') v_categories = jsn.get('v_categories', '') spcall('updatevenue', (v_id, v_name, v_email_address, v_description, v_location, v_capacity, v_pricing, v_categories), True) return jsonify({"status": "OK"})
def store_appointment(): jsn = json.loads(request.data) res = spcall('newappointment', (jsn['event_id'], jsn['client'], jsn['about'], jsn['app_date'], jsn['app_time'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]}), 200
def store_contract(): data = json.loads(request.data) res = spcall('new_contract', (data['event_id'], data['contract_reference'], data['client_name'], data['termsOfAgreement'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]}), 200
def feedback(): """ Creating a Feedback """ res = spcall("newfeedback", (request.form['name'], request.form['comment'], request.form['hotel_id'])) if 'Error' in res[0][0]: return jsonify({'status': 'error', 'message': res[0][0]}) return jsonify({'status': 'ok', 'message': res[0][0]})
def store_proposal(): jsn = json.loads(request.data) res = spcall( 'new_proposal', (jsn['event_id'], jsn['name'], jsn['address'], jsn['proposal_num'], jsn['proposal_name'], jsn['proposal_date']), True) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]}), 200
def get_roomid(id): res = spcall('getid_room', [id]) if not res: return jsonify({'status': 'error', 'message': 'Results Not Found'}),404 recs = res[0] return jsonify({'room_number' : str(recs[0]), 'cost': str(recs[1]), 'room_type': str(recs[2])})
def view_feedback(id): """ Viewing Specific Feedback """ res = spcall("getfeedback", id, True) recs = [] for r in res: recs.append({"id": int(r[0]), "name": r[1], "comment": r[2], "created_date": r[3]}) return jsonify({'status': 'ok', 'entries': recs, 'count': len(recs)})
def login(): json_data = request.json res = spcall("getid_personnel", (json_data['lname']), True) if res and 'gwapa' == json_data['password']: session['logged_in'] = True status = True else: status = False return jsonify({'result': status})
def add_catering(): jsn = json.loads(request.data) res = spcall('newcatering', (jsn['c_name'], jsn['c_email_address'], jsn['c_description'], jsn['c_location'], jsn['c_pricing'], jsn['c_categories'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def add_event(): jsn = json.loads(request.data) res = spcall( 'newevent', (jsn['user_id'], jsn['title'], jsn['date_event'], jsn['time_event'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def search(location): """ Searching a hotel through its location """ res = spcall("location_search", [location], True) recs = [] for r in res: recs.append({"id_hotel": int(r[0]), "hotel_name": r[1], "description": r[2], "email_address": r[3], "address": r[4], "contact_number": r[5], "no_of_restaurant": int(r[6]), "no_of_rooms": int(r[7]), "extra": r[8]}) return jsonify({'status': 'ok', 'entries': recs, 'count': len(recs)})
def add_venue(): jsn = json.loads(request.data) res = spcall('newvenue', (jsn['v_name'], jsn['v_email_address'], jsn['v_description'], jsn['v_location'], jsn['v_capacity'], jsn['v_pricing'], jsn['v_categories'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def updatenote(): data = json.loads(request.data) id = data['id'] title = data['title'] note = data['note'] res = spcall('updatenote', (id, title, note), True) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def updatecontract(): data = json.loads(request.data) id = data['id'] contract_reference = data['contract_reference'] client_name = data['client_name'] termsOfAgreement = data['termsOfAgreement'] res = spcall('update_contract', (id, contract_reference, client_name, termsOfAgreement), True) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def get_event(id): res = spcall('get_event', [id]) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) rec = res[0] return jsonify({ "title": str(rec[0]), "date_event": str(rec[1]), "time_event": str(rec[2]) })
def updateappointment(): jsn = json.loads(request.data) id = jsn['id'] client = jsn['client'] about = jsn['about'] app_date = jsn['app_date'] app_time = jsn['app_time'] res = spcall('update_appointment', (id, client, about, app_date, app_time), True) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def add_room(): req = json.loads(request.data) res = spcall("newroom", ( req['room_number'], req['cost'], req['room_type'], req['hotel_id'] )) if 'Error' in res[0][0]: return jsonify({'status': 'error', 'message': res[0][0]}) return jsonify({'status': 'ok', 'message': res[0][0]})
def signup(): jsn = json.loads(request.data) if invalid(jsn['email_address']): return jsonify({'status': 'Error', 'message': 'Invalid Email address'}) res = spcall( 'newuser', (jsn['email_address'], jsn['fname'], jsn['lname'], jsn['password'], jsn['address'], jsn['birthdate'], jsn['age'])) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def getspecificuser(user_id): res = spcall('getuser', [user_id]) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) rec = res[0] return jsonify({ "email_address": str(rec[0]), "fname": str(rec[1]), "lname": str(rec[2]), "address": str(rec[3]), "birthdate": str(rec[4]), "age": str(rec[5]) })
def register(): req = request.json password = req['password'] fname = req['fname'] lname = req['lname'] mname = req['mname'] res = spcall("newHotel_Personnel", (fname, mname, lname, password, 1), True) if 'Error' in res[0][0]: status = 'this user is already registered' else: status = 'success' return jsonify({'result': status})
def updateproposal(): data = json.loads(request.data) id = data['id'] name = data['name'] address = data['address'] proposal_num = data['proposal_num'] proposal_name = data['proposal_name'] proposal_date = data['proposal_date'] res = spcall( 'update_proposal', (id, name, address, proposal_num, proposal_name, proposal_date), True) if 'Error' in str(res[0][0]): return jsonify({'status': 'Error', 'message': res[0][0]}) return jsonify({'status': 'OK', 'message': res[0][0]})
def getnote(n_id): res = spcall('show_note', (n_id, )) recs = [] if len(res) == 0: return jsonify({ "status": "error", "message": "No entries found", "entries": [] }) elif 'Error' in str(res[0][0]): return jsonify({"status": "error", "message": res[0][0]}) else: for r in res: recs.append({"id": r[0], "title": str(r[1]), "note": r[2]}) return jsonify({"status": "OK", "message": "OK", "entries": recs})
def getspecificcater(id): res = spcall('show_cater', [id]) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) rec = res[0] return jsonify({ "c_name": str(rec[0]), "c_email_address": str(rec[1]), "c_description": str(rec[2]), "c_location": str(rec[3]), "c_pricing": str(rec[4]), "c_categories": str(rec[5]) })
def get_rooms(): res = spcall('getroom', ()) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) recs = [] for r in res: recs.append({ "id": int(r[0]), "room_number": r[1], "cost": (r[2]), "room_type": str(r[3]) }) return jsonify({'status': 'ok', 'entries': recs, 'count': len(recs)})
def login(): data = request.json res = spcall("loginauth", (data['email_address'], data['password'])) if res == 'ERROR': status = False return jsonify({'status': status, 'message': 'error'}) else: status = True token = jwt.dumps({'user': data['email_address']}) return jsonify({ 'status': status, 'token': token, 'id': res, 'message': 'success' })
def getspecificvenue(id): res = spcall('show_venue', [id]) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) rec = res[0] return jsonify({ "v_name": str(rec[0]), "v_email_address": str(rec[1]), "v_description": str(rec[2]), "v_location": str(rec[3]), "v_capacity": str(rec[4]), "v_pricing": str(rec[5]), "v_categories": str(rec[6]) })
def updateroom(): jsn = json.loads(request.data) id_room = jsn.get('id_room','') room_number = jsn.get('room_number', '') cost = jsn.get('cost', '') room_type = jsn.get('room_type', '') res = spcall('updateroom', ( id_room, room_number, cost, room_type),True) return jsonify({"status": "success"}) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]})
def getcontract(id): res = spcall('show_contract', (id, )) recs = [] if len(res) == 0: return jsonify({ "status": "error", "message": "No entries found", "entries": [] }) elif 'Error' in str(res[0][0]): return jsonify({"status": "error", "message": res[0][0]}) else: for r in res: recs.append({ "id": r[0], "reference": r[1], "client_name": r[2], "termsOfAgreement": r[3] }) return jsonify({"status": "OK", "message": "OK", "entries": recs})
def getappointment(id): res = spcall('show_appointment', (id, )) recs = [] if len(res) == 0: return jsonify({ "status": "error", "message": "No entries found", "entries": [] }) elif 'Error' in str(res[0][0]): return jsonify({"status": "error", "message": res[0][0]}) else: for r in res: recs.append({ "id": r[0], "client": str(r[1]), "about": str(r[2]), "app_date": str(r[3]), "app_time": str(r[4]) }) return jsonify({"status": "OK", "message": "OK", "entries": recs})
def get_all_venue(): res = spcall('showall_venues', ()) if 'Error' in str(res[0][0]): return jsonify({'status': 'error', 'message': res[0][0]}) recs = [] for r in res: recs.append({ "v_name": str(r[0]), "v_email_address": str(r[1]), "v_description": str(r[2]), "v_location": str(r[3]), "v_capacity": str(r[4]), "v_pricing": str(r[5]), "v_categories": str(r[6]) }) return jsonify({'status': 'ok', 'entries': recs, 'count': len(recs)}) if len(res) > 0: for r in res: recs.append({ "v_name": str(r[0]), "v_email_address": str(r[1]), "v_description": str(r[2]), "v_location": str(r[3]), "v_capacity": str(r[4]), "v_pricing": str(r[5]), "v_categories": str(r[6]) }) return jsonify({ 'status': 'ok', 'entries': recs, 'count': len(recs) }) else: return jsonify({'status': 'no entries in database'})
def getproposal(id): res = spcall('show_proposal', (id, )) recs = [] if len(res) == 0: return jsonify({ "status": "error", "message": "No entries found", "entries": [] }) elif 'Error' in str(res[0][0]): return jsonify({"status": "error", "message": res[0][0]}) else: for r in res: recs.append({ "id": r[0], "name": r[1], "address": r[2], "propsal_num": str(r[3]), "proposal_name": r[4], "proposal_date": str(r[5]) }) return jsonify({"status": "OK", "message": "OK", "entries": recs})