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 = Booking.parser.parse_args() booking = BookingModel(**data) try: booking.save_to_db() except: return {"message": "An error occurred inserting the booking."}, 500 return booking.json(), 201
def get(self): id = request.args.get('id', None) user_id = request.args.get('user_id', None) print(id, 'haha') if id: booking = BookingModel.find_by_id(id) else: booking = BookingModel.find_by_user_id(user_id) if booking: if id: return booking.json() else: return booking.json_multiple() return {'message': 'booking not found'}, 404
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 put(self): data = Booking.parser.parse_args() userid = data['userid'] bikeid = data['bikeid'] user = AccountsModel.find_by_id(userid) bike = MotosModel.find_by_id(bikeid) if user is None: return "User not found", 404 if bike is None: return "Bike not found", 404 try: admin_user = AccountsModel.find_by_username('admin') if admin_user: book = BookingModel.finalize_book(userid, bikeid) if book is None: return "No renting found", 404 MotosModel.change_status(bikeid) admin_user.availableMoney += book.price user.availableMoney -= book.price return {"finalized_rent": book.json()}, 201 return "Admin user not found", 404 except: return "Something went wrong", 500
def get(self, userid): rents = BookingModel.find_by_userid(userid) if len(rents) == 1: return {"rents": rents.json()}, 200 if len(rents) > 1: return {"rents": [rent.json() for rent in rents]}, 200 return { "Error": "There are no rents for user with id {}".format(userid) }, 404
def post(self): data = Booking.parser.parse_args() userid = data['userid'] bikeid = data['bikeid'] user = AccountsModel.find_by_id(userid) bike = MotosModel.find_by_id(bikeid) if user is None: return "User not found", 404 if bike is None: return "Bike not found", 404 moto_active = MotosModel.is_active(bikeid) try: if user.availableMoney > 5: if moto_active is True: new_rent = BookingModel(userid, bikeid, None, None, None) new_rent.startDate = datetime.now() MotosModel.change_status(bikeid) new_rent.save_to_db() return {"new_rent": new_rent.json()}, 201 return "Moto selected is not active", 400 return "Not money enough", 400 except: return "Something went wrong", 500
def post(self, ticket_id): id = ticket_id user_from_token = get_jwt_identity() user = UsersModel.query.filter_by(email=user_from_token).first() ticket = TicketModel.query.get(id) if not ticket: return {"message": "Not found booking"}, 404 price = request.json['price'] seat_no = request.json['seat_no'] # counterSeat = request.json['counterSeat'] # price = ticket.price_per_seat*counterSeat # print(price) created_at = str(datetime.now()) new_booking = BookingModel(user_id=user.id, ticket_id=ticket_id, price=price, seat_no=seat_no, created_at=created_at) db.session.add(new_booking) db.session.commit() return {"message": "Thank For Booking Ticket"}
def get(self): return BookingModel.list_orders()