Example #1
0
class UAVBatteryStatistic(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self, battery_status):
        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)

            rs = self.dao.query_statistic(user, battery_status)
            if rs == -1:
                return make_response(jsonify({'error': 'Unauthorized access'}),
                                     401)
            else:
                return rs
        else:
            return make_response(jsonify({'error': 'Unauthorized access'}),
                                 401)

    def get(self, battery_status):
        return self.post(battery_status)
Example #2
0
class UAVBatteryStatistic(Resource):
    def __init__(self):
        self.dao = BatteryDAO()
        self.userDao = UserDAO()

    def post(self, battery_status):
        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)

            rs = self.dao.query_statistic(user, battery_status)
            if rs == None:
                return make_response(
                    jsonify({
                        'error': '获取统计信息失败',
                        'errorcode': 10000000
                    }), 401)
            else:
                return rs
        else:
            return make_response(
                jsonify({
                    'error': '输入参数错误',
                    'errorcode': 10000000
                }), 401)

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