Exemplo n.º 1
0
    def delete(self, id_):
        if not id_:
            raise RequestException(400, 'ID path param is required')

        id_ = int(id_)
        user = self._controller.find(id_)
        if not user:
            raise RequestException(404, 'User not founded')

        self._controller.delete(user)

        return {'success': {'text': 'Usuário removido'}}
Exemplo n.º 2
0
    def delete(self, id_):
        if not id_:
            raise RequestException(400, 'ID path param is required')

        id_ = int(id_)
        order = self._controller.find(id_)
        if not order:
            raise RequestException(404, 'Order not founded')

        self._controller.delete(order)

        return {
            'success': {
                'text': 'Comanda removida'
            }
        }
Exemplo n.º 3
0
    def put(self, id_):
        if not id_:
            raise RequestException(400, 'ID path param is required')

        if not request.is_json:
            raise RequestException(400, 'Must be JSON request')

        id_ = int(id_)
        order = self._controller.find(id_)
        if not order:
            raise RequestException(404, 'Order not founded')

        body = request.json
        self._controller.update_order_data(order, body)

        return order_to_dict(order)
Exemplo n.º 4
0
    def get_required_value(cls, body, key):
        value = body.get(key)

        if not value:
            raise RequestException(400, f'{key} is required')

        return value
Exemplo n.º 5
0
    def post(self):
        if not request.is_json:
            raise RequestException(400, 'Must be JSON request')

        body = request.json

        order = self._controller.new_order(body)

        return order_to_dict(order), 201
Exemplo n.º 6
0
    def post(self):
        if not request.is_json:
            raise RequestException(400, 'Must be JSON request')

        body = request.json

        user = User(email=body['email'], password=body['senha'])

        self._controller.update(entity=user)

        return user_to_dict(user), 201
Exemplo n.º 7
0
    def new_order(self, body: dict):
        user_id = int(self.get_required_value(body, 'idusuario'))
        products = self.get_required_value(body, 'produtos')
        total_value = float(self.get_required_value(body, 'valortotal'))

        from rest.controller.user import UserController
        user = UserController().find(user_id)

        if not user:
            raise RequestException(404, 'User not founded')

        order = Order(
            user=user,
            products=products,
            total_value=total_value
        )

        self._dao.update(order)

        return order
Exemplo n.º 8
0
    def update_order_data(self, order: Order, body: dict):
        keys = body.keys()

        if 'idusuario' in keys:
            user_id = body.get('idusuario')

            from rest.controller.user import UserController
            user = UserController().find(user_id)

            if not user:
                raise RequestException(404, 'User not founded')

            order.user = user

        if 'produtos' in keys:
            order.products = body.get('produtos')

        if 'valortotal' in keys:
            order.total_value = float(body.get('valortotal'))

        self._dao.update(order)