Example #1
0
    def put(self, contact_uuid):
        '''
            Replace contact
        '''
        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.request.body)

        logging.info('put received struct {0}'.format(struct))

        format_pass = (True if not struct.get('errors') else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        account = self.request.arguments.get('account', [None])[0]

        result = yield self.replace_contact(account, contact_uuid, struct)

        if not result:
            self.set_status(400)
            system_error = errors.Error('missing')
            error = system_error.missing('contact', contact_uuid)
            self.finish(error)
            return

        self.set_status(200)
        self.finish({'message': 'replace completed successfully'})
Example #2
0
    def patch(self, contact_uuid):
        '''
            Modify contact
        '''
        logging.info('request.arguments {0}'.format(self.request.arguments))
        logging.info('request.body {0}'.format(self.request.body))

        struct = yield check_json(self.request.body)

        logging.info('patch received struct {0}'.format(struct))

        format_pass = (True if not dict(struct).get('errors', False) else False)
        if not format_pass:
            self.set_status(400)
            self.finish({'JSON':format_pass})
            return

        account = self.request.arguments.get('account', [None])[0]

        if not account:
            # if not account we try to get the account from struct
            account = struct.get('account', None)

        logging.warning('account {0} uuid {1}'.format(account, contact_uuid))

        result = yield self.modify_contact(account, contact_uuid, struct)

        if not result:
            self.set_status(400)
            system_error = errors.Error('missing')
            error = system_error.missing('contact', contact_uuid)
            self.finish(error)
            return

        self.set_status(200)
        self.finish({'message': 'update completed successfully'})