コード例 #1
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def attend_request(self, id_request, *args, **kwargs):
        db = Database()
        attended_request = {
            'id': id_request,
            'id_driver': self.id,
            'status': Request.REQUEST_STATUS.get('ongoing')
        }
        request = Request(**attended_request)
        db.update(request)

        driver = Driver(**{'id': self.id, 'current_request': id_request})
        db.update(driver)

        new_history = {
            'id_request': request.id,
            'old_status': Request.REQUEST_STATUS.get('new'),
            'new_status': Request.REQUEST_STATUS.get('ongoing'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        return {
            'request': object_to_dict(request),
            'msg': 'Request attended successfully'
        }
コード例 #2
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def deliver_request(self, id_request, delivery_code):
        db = Database()
        code_search = db.query(
            f"SELECT * FROM delivery_codes WHERE code = '{delivery_code}'")
        id_collector = code_search[0][1]
        delivered_request = {
            'id': id_request,
            'id_collector': id_collector,
            'status': Request.REQUEST_STATUS.get('evaluation')
        }
        request = Request(**delivered_request)
        db.update(request)

        driver = Driver(**{'id': self.id, 'current_request': None})
        db.update(driver)

        dc = db.get(DeliveryCode, code_search[0][0])
        db.delete(dc)

        new_history = {
            'id_request': request.id,
            'old_status': Request.REQUEST_STATUS.get('ongoing'),
            'new_status': Request.REQUEST_STATUS.get('evaluation'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        return {
            'request': object_to_dict(request),
            'msg': 'Request delivered successfully'
        }
コード例 #3
0
ファイル: add.py プロジェクト: nathangngencissk/recicly
def handle(event, context):
    body = json.loads(event.get('body'))

    collector = Collector(**body)

    db = Database()

    db.add(collector)

    collector.__dict__.pop('_sa_instance_state')

    response = {
        'statusCode':
        200,
        'headers': {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Credentials': True
        },
        'body':
        json.dumps({
            'collector': collector.__dict__,
            'msg': f'Collector {collector.id} added successfully'
        }),
    }

    return response
コード例 #4
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
 def exchange_points(self, product_id, *args, **kwargs):
     db = Database()
     product = db.get(Product, product_id)
     if self.points < product.price:
         return {'msg': 'Insufficient points'}
     user = User(**{'id': self.id, 'points': self.points - product.price})
     db.update(user)
     order = Order(id_user=self.id,
                   id_product=product.id,
                   timestamp=str(datetime.datetime.now().timestamp()))
     db.add(order)
     return {'msg': f'{product.name} bought successfully'}
コード例 #5
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def receive_request(self, *args, **kwargs):
        code = self.generate_delivery_code()

        db = Database()

        delivery_code = DeliveryCode(**{'collector_id': self.id, 'code': code})

        db.add(delivery_code)

        return {
            'delivery_code': object_to_dict(delivery_code),
            'msg': 'Delivery code generated successfully'
        }
コード例 #6
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def approve_request(self, id_request, *args, **kwargs):
        db = Database()

        approved_request = {
            'id': id_request,
            'status': Request.REQUEST_STATUS.get('approved')
        }
        request = Request(**approved_request)
        db.update(request)

        new_history = {
            'id_request': request.id,
            'old_status': Request.REQUEST_STATUS.get('waiting_approval'),
            'new_status': Request.REQUEST_STATUS.get('approved'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        updated_user = {
            'id': self.id,
            'points': self.points + db.get(Request, id_request).points
        }
        user = User(**updated_user)
        db.update(user)

        req = db.get(Request, id_request)
        id_driver = req.id_driver

        drv = db.get(Driver, id_driver)

        updated_driver = {
            'id': id_driver,
            'points': drv.points + (req.points / 2)
        }
        driver = Driver(**updated_driver)
        db.update(driver)

        request.status = Request.REQUEST_STATUS.get('concluded')
        db.update(request)

        return {
            'request': object_to_dict(request),
            'msg': 'Request approved successfully'
        }
コード例 #7
0
ファイル: add.py プロジェクト: nathangngencissk/recicly
def handle(event, context):
    body = json.loads(event.get('body'))

    driver = Driver(**body)

    db = Database()

    db.add(driver)

    driver.__dict__.pop('_sa_instance_state')

    response = {
        'statusCode': 200,
        'body': json.dumps({
            'driver': driver.__dict__,
            'msg': f'Driver {driver.id} added successfully'
        }),
    }

    return response
コード例 #8
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def evaluate_request(self, id_request, weight, *args, **kwargs):
        db = Database()
        request_evaluated = {
            'id': id_request,
            'status': Request.REQUEST_STATUS.get('concluded'),
            'weight': weight,
            'points': weight / 5
        }
        request = Request(**request_evaluated)
        db.update(request)

        new_history = {
            'id_request': request.id,
            'old_status': Request.REQUEST_STATUS.get('evaluation'),
            'new_status': Request.REQUEST_STATUS.get('concluded'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        req = db.get(Request, id_request)

        us = db.get(User, req.id_user)
        updated_user = {'id': us.id, 'points': us.points + req.points}
        user = User(**updated_user)
        db.update(user)

        drv = db.get(Driver, req.id_driver)

        updated_driver = {
            'id': req.id_driver,
            'points': drv.points + (req.points / 2)
        }
        driver = Driver(**updated_driver)
        db.update(driver)

        return {
            'request': object_to_dict(request),
            'msg': 'Request evaluated successfully'
        }
コード例 #9
0
ファイル: add.py プロジェクト: nathangngencissk/recicly
def handle(event, context):
    body = json.loads(event.get('body'))

    product = Product(**body)

    db = Database()

    db.add(product)

    product.__dict__.pop('_sa_instance_state')

    response = {
        'statusCode':
        200,
        'body':
        json.dumps({
            'product': product.__dict__,
            'msg': f'Product {product.id} added successfully'
        }),
    }

    return response
コード例 #10
0
ファイル: add.py プロジェクト: nathangngencissk/recicly
def handle(event, context):
    body = json.loads(event.get('body'))

    adress = Adress(**body)

    db = Database()

    db.add(adress)

    adress.__dict__.pop('_sa_instance_state')

    response = {
        'statusCode':
        200,
        'body':
        json.dumps({
            'adress': adress.__dict__,
            'msg': f'Adress {adress.id} added successfully'
        }),
    }

    return response
コード例 #11
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def contest_request(self, id_request, *args, **kwargs):
        db = Database()
        contested_request = {
            'id': id_request,
            'status': Request.REQUEST_STATUS.get('contested')
        }
        request = Request(**contested_request)
        db.update(request)

        new_history = {
            'id_request': request.id,
            'old_status': Request.REQUEST_STATUS.get('waiting_approval'),
            'new_status': Request.REQUEST_STATUS.get('contested'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        return {
            'request': object_to_dict(request),
            'msg': 'Request contested successfully'
        }
コード例 #12
0
ファイル: __init__.py プロジェクト: nathangngencissk/recicly
    def start_request(self, address_id, *args, **kwargs):
        db = Database()
        new_request = {
            'id_user': self.id,
            'id_address': address_id,
            'status': Request.REQUEST_STATUS.get('new')
        }

        request = Request(**new_request)
        db.add(request)

        new_history = {
            'id_request': request.id,
            'new_status': Request.REQUEST_STATUS.get('new'),
            'timestamp': str(datetime.datetime.now().timestamp())
        }

        history = History(**new_history)
        db.add(history)

        return {
            'request': object_to_dict(request),
            'msg': 'Request started successfully'
        }