def post(self): data = Booking.parser.parse_args() new_pnr = BookingModel.new_pnr() new_ticket = BookingModel(new_pnr, data['doj'], data['fare'], data['passport'], data['bank_name'], data['card'], data['route_id']) try: new_ticket.insert() except: return {'message': 'Unfortunate error occurred'}, 500 flight = FlightModel.find_by_number(data['route_id']) flight_information = flight.json() flight_information.update({ 'equipment': 'Boeing 737MAX', 'fare': flight_information['fare'], 'bank_name': flight_information['bank_name'], 'card': flight_information['card'], 'class_booked': flight_information['_class'] }) contact = ContactModel.find_contact(data['passport']) contact_information = contact.json() flight_information.update({ 'passport': contact_information['passport'], 'date_of_birth': contact_information['dob'], 'phone': contact_information['phone'], 'email_id': contact_information['email_id'], 'first_name': contact_information['first_name'], 'last_name': contact_information['last_name'] }) return flight_information, 201
def post(self): data = ViewBooking.parser.parse_args() view_ticket = BookingModel.get_booking(data['pnr']) flight = FlightModel.find_by_number(data['route_id']) flight_information = flight.json() view_ticket.update({ 'destination': flight_information['destination'], 'source': flight_information['source'], 'departure_time': flight_information['departure_time'], 'arrival_time': flight_information['arrival_time'] }) view_ticket.update({ 'equipment': 'Boeing 737MAX', 'class_booked': data['_class'] }) contact = ContactModel.find_contact(data['passport']) contact_information = contact.json() view_ticket.update({ 'date_of_birth': contact_information['dob'], 'phone': contact_information['phone'], 'email_id': contact_information['email_id'], 'first_name': contact_information['first_name'], 'last_name': contact_information['last_name'] }) return view_ticket, 200
def get(self, passport): try: contact = ContactModel.find_contact(passport) except: return {'message': 'Unfortunate error occurred'}, 500 if contact: return contact.json(), 200 return {'message': "Contact doesn't exists"}, 404
def post(self, passport): if ContactModel.find_contact(passport): return {'message': 'contact already exist'}, 400 data = Contact.parser.parse_args() contact = ContactModel(passport, data['dob'], data['phone'], data['email_id'], data['first_name'], data['last_name']) try: contact.insert() except: return {'message': 'Unfortunate error occurred'}, 500 return contact.json(), 201
def put(self, passport): data = Contact.parser.parse_args() contact = ContactModel.find_contact(passport) new_contact = ContactModel(passport, data['dob'], data['phone'], data['email_id'], data['first_name'], data['last_name']) if contact: try: new_contact.update() except: return {'message': "Couldn't update"}, 500 return new_contact.json(), 200 try: new_contact.insert() except: return {'message': "Couldn't insert"}, 500 return new_contact.json(), 201