class UAVBatteryList(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            args = parser.parse_args()
            battery_status = args.get('battery_status')
            battery_type = args.get('battery_type')
            page_index = args.get('page_index')
            page_size = args.get('page_size')
            return self.dao.query_condition(user, None, None, battery_type,
                                            battery_status, page_index,
                                            page_size)
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self):
        return self.post()
Exemple #2
0
class UAVBatteryList(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            args = parser.parse_args()
            battery_status = args.get('battery_status')
            battery_type = args.get('battery_type')
            page_index = args.get('page_index')
            page_size = args.get('page_size')
            return self.dao.query_condition(user, None, None, battery_type,
                                            battery_status, page_index,
                                            page_size)
        else:
            return make_response(
                jsonify({
                    'error': '输入参数有误',
                    'errorcode': 10000000
                }), 401)

    def get(self):
        return self.post()
Exemple #3
0
class UAVBatteryGetID(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self):
        if (request.data != ""):
            data = json.loads(request.data)
            token = data['token']
            battery_id = data['battery_id']
            user = self.userDao.verify_token(token, '')
            if (not user):
                return make_response(
                    jsonify({
                        'error': '用户不存在或登录过期',
                        'errorcode': 10000000
                    }), 400)
            if user == 1010301:
                return make_response(
                    jsonify({
                        'error': '登录过期',
                        'errorcode': user
                    }), 400)
            if user == 1010302:
                return make_response(
                    jsonify({
                        'error': '用户验证错误',
                        'errorcode': user
                    }), 400)

            return self.dao.query_condition(user, battery_id, None, None, None,
                                            1, 1)
        else:
            return make_response(
                jsonify({
                    'error': '输入数据有误',
                    'errorcode': 1000000
                }), 401)

    def get(self):
        return self.post()