コード例 #1
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
コード例 #2
0
    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
コード例 #3
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