Ejemplo n.º 1
0
    def post(self):
        json_data = request.get_json(force=True)
        header = request.headers["Authorization"]

        if not json_data:

            return {'message': 'No input data provided'}, 400
        if not header:
            return {"Messege": "No api key!"}, 401
        else:
            user = User.query.filter_by(api_key=header).first()
        if not user:
            return {'message': 'User ID not available'}, 402

        accepted_order = Accepted_Order.query.filter_by(
            order_id=json_data['order_id']).first()

        if not accepted_order:
            return {'message': 'order ID not available'}, 403

        user = User.query.filter_by(user_id=json_data['user_id']).first()

        notification = Notification(
            user_id=json_data['user_id'],
            order_id=json_data['order_id'],
            notification_content=json_data['notification_content'],
            driver_mode=user.driver_mode)
        db.session.add(notification)
        db.session.commit()

        result = Notification.serialize(notification)

        return {"status": 'success', 'data': result}, 201
    def post(self):
        json_data = request.get_json(force=True)

        if not json_data:
            return {'message': 'No input data provided'}, 400

        notification = Notification.query.filter_by(
            notification_id=json_data['notification_id']).first()
        if not Notification:
            return {'message': 'Notification id not available'}, 400

        notification.status = True
        db.session.commit()
        result = Notification.serialize(notification)

        return {"status": 'success', 'data': result}, 201