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
Beispiel #2
0
 def delete(self, username):
     contact = ContactModel.find_by_username(username)
     if contact:
         contact.delete_from_db()
         return {'message': 'contact deleted'}
     else:
         return {'message': 'contact not found'}
    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 post(self):
        data = UpdateContact.parser.parse_args()
        new_contact = ContactModel(data['passport'], data['dob'],
                                   data['phone'], data['email_id'],
                                   data['first_name'], data['last_name'])

        try:
            new_contact.insert()
        except:
            return {'message': 'Unfortunate error occurred'}, 500

        return {
            'route_id': data['route_id'],
            'final_fare': data['fare'],
            'doj': data['doj'],
            'class_booked': data['_class'],
            'passport': data['passport']
        }, 201
Beispiel #5
0
    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
Beispiel #6
0
 def post(self):
     data = _contact_parser.parse_args()
     if ContactModel.find_by_username(data["username"]):
         return {
             'message':
             "A contact with username '{}' already exists.".format(
                 data["username"])
         }, 400
     else:
         recordtime = str(datetime.datetime.now()).split('.')[0]
         contact = ContactModel(data["username"], data["firstname"],
                                data["lastname"], recordtime)
         try:
             contact.save_to_db()
             return {"message": "Contact created successfully."}, 201
         except:
             return {
                 "message": "Error occured while inserting new contact "
             }, 404
Beispiel #7
0
 def put(self):
     data = _contact_parser.parse_args()
     x = ContactModel.find_by_username(data["username"])
     print("x", x)
     if ContactModel.find_by_username(data["username"]):
         try:
             contact = ContactModel.find_by_username(data["username"])
             contact.username = data["username"]
             contact.firstname = data["firstname"]
             contact.lastname = data["lastname"]
             contact.recordtime = str(datetime.datetime.now()).split('.')[0]
             db.session.commit()
             return {"message": "Contact updated successfully."}, 201
         except:
             return {"message": "Error while updating the Contact"}, 404
     return {
         "message":
         "Sorry there is no contact with this username to update."
     }, 404
Beispiel #8
0
 def put(self):
     data = _contact_parser.parse_args()
     if ContactModel.find_by_username(data["username"]):
         try:
             contact = ContactModel.find_by_username(data["username"])
             contact.username = data["username"]
             contact.firstname = data["firstname"]
             contact.lastname = data["lastname"]
             recordtime = str(datetime.datetime.now()).split('.')[0]
             contact.recordtime = recordtime
             db.session.commit()
             return {"message": "Contact updated successfully."}, 201
         except:
             return {"message": "Error while updating the Contact"}, 404
     else:
         return {
             "message":
             "Sorry there is no user called '{}'exists to update.".format(
                 data["username"])
         }, 404
Beispiel #9
0
    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
Beispiel #10
0
    def randomcreatedelete(self, delay):
        next_time = time.time() + delay
        while True:
            time.sleep(max(0, next_time - time.time()))
            username = ''.join([
                random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(10)
            ])
            firstname = ''.join([
                random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(20)
            ])
            lastname = ''.join([
                random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(20)
            ])
            recordtime = str(datetime.datetime.now()).split('.')[0]
            next_time += (time.time() - next_time) // delay * delay + delay
            print(username, firstname, lastname, recordtime, recordtime_dt)

            # Adding a record for every 15 secods
            if ContactModel.find_by_username(username):
                return {
                    'message':
                    "A contact with username '{}' already exists.".format(
                        username)
                }, 400
            else:
                contact = ContactModel(username, firstname, lastname,
                                       recordtime)
                try:
                    contact.save_to_db()
                    return {"message": "Contact created successfully."}, 201
                except:
                    return {
                        "message": "Error occured while inserting new contact "
                    }, 404

            #Delete a record if it is created earlier than 1 min
            contacts = {
                list(map(lambda x: x.json(), ContactModel.query.all()))
            }
            for rec in contacts:
                recordtime_dt = datetime.datetime.strptime(
                    rec["recordtime"], '%Y-%m-%d %H:%M:%S')
                timegap = int(
                    (datetime.datetime.now() - recordtime_dt).total_seconds())
                if timegap > 60:
                    contact.delete_from_db()
                    return {'message': 'contact deleted'}
Beispiel #11
0
    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
Beispiel #12
0
 def get(self, username):
     contact = ContactModel.find_by_username(username)
     if contact:
         return contact.json()
     return {'message': 'contact not found'}, 404