コード例 #1
0
ファイル: ws.py プロジェクト: zefranlopes/notifyshipping
    async def put_notify(self, request):
        '''
            Objective............: Method PUT for URL Notify Update
            Parameters...........: 
                request..........: Data of the Requests from Consumption API 
            Return...............: Response Object JSON
        '''
        try:
            self.log.info('ws|put_notify|ini')
            id = request.match_info.get('id', '')
            if not id:
                raise ApiNotifyShippingException('No QueryString "/id" is Present in the Request. Verify your Request and Try Again')

            if not request.body_exists:
                raise ApiNotifyShippingException('No Body is Present in the Request. Verify your Request and Try Again')

            data = await request.json()
            data = self.NY.put_notify(id, data.get('data'))

            return self.eco(data=data, status=202, message='Notify Successfully Update')

        except Exception as e:
            self.log.error('ws|put_notify|error')
            self.log.error(str(e))            
            self.log.error(traceback.format_exc())
            return self.eco(data=None, status=500, message=str(e))
        finally:
            self.log.info('ws|put_notify|fin')   
コード例 #2
0
    def put_notify(self, id, data):
        '''
            Objective............: Method PUT for URL /notify/id
            Parameters...........: 
                id...............: ID Reference Data Object of the Notify
                data.............: Data Object Json of the Notify
            Return...............: Response Object JSON
        '''
        try:
            self.ws.log.info('notify|put_notify|ini')

            #FIXME Waning for Cost Time.
            session = self.ws.DB.session()

            NM = session.query(NotifyModel).get(id)
            NM.ts_updt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            NM.ts_recv = data.get('ts_recv')
            NM.ts_send = data.get('ts_send')
            NM.status = data.get('status')
            NM.remittee = data.get('remittee')
            NM.payload = data.get('payload')

            session.commit()

            return NM.to_dict()

        except Exception as e:
            self.ws.log.error('notify|put_notify|error')
            self.ws.log.error(str(e))
            self.ws.log.error(traceback.format_exc())
            raise ApiNotifyShippingException(str(e))
        finally:
            self.ws.log.info('notify|put_notify|fin')
コード例 #3
0
    def del_notify(self, id):
        '''
            Objective............: Method DELETE for URL /notify/id
            Parameters...........: 
                id...............: ID Reference Data Object of the Notify
            Return...............: Response Object JSON
        '''
        try:
            self.ws.log.info('notify|del_notify|ini')

            #FIXME Waning for Cost Time.
            session = self.ws.DB.session()
            NM = session.query(NotifyModel).get(id)
            session.delete(NM)
            session.commit()

            return {} if not NM else NM.to_dict()

        except Exception as e:
            self.ws.log.error('notify|del_notify|error')
            self.ws.log.error(str(e))
            self.ws.log.error(traceback.format_exc())
            raise ApiNotifyShippingException(str(e))
        finally:
            self.ws.log.info('notify|del_notify|fin')
コード例 #4
0
    def post_notify(self, data):
        '''
            Objective............: Method POST for URL /profile
            Parameters...........: 
                data.............: Data Object Json of the Notify
            Return...............: Response Object JSON
        '''
        try:
            self.ws.log.info('notify|post_notify|ini')

            #FIXME Waning for Cost Time.
            session = self.ws.DB.session()

            NM = NotifyModel()
            data['id'] = hashlib.md5(
                f'{NM.ts_updt}{NM.ts_send}{NM.remittee}'.encode()).hexdigest()
            data['ts_updt'] = datetime.datetime.now().strftime(
                "%Y-%m-%d %H:%M:%S")
            NM.id = data['id']
            NM.ts_updt = data['ts_updt']
            NM.ts_recv = data.get('ts_recv')
            NM.ts_send = data.get('ts_send')
            NM.status = data.get('status')
            NM.remittee = data.get('remittee')
            NM.payload = data.get('payload')

            #TODO Return Notify ID or UUID of the DataBase
            data['id'] = NM.id

            self.ws.log.debug(NM)

            session.add(NM)
            session.commit()

            return data

        except Exception as e:
            self.ws.log.error('notify|post_notify|error')
            self.ws.log.error(str(e))
            self.ws.log.error(traceback.format_exc())
            raise ApiNotifyShippingException(str(e))
        finally:
            self.ws.log.info('notify|post_notify|fin')