Пример #1
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
Пример #2
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