()
接口信息增加、编辑
接口信息增加、编辑
接口信息增加、编辑
def add_api_msg():
    """ 接口信息增加、编辑 """
    data = request.json
    project_id = data.get('projectId')
    api_msg_name = data.get('apiMsgName')
    variable_type = data.get('variableType')
    desc = data.get('desc')
    header = data.get('header')
    extract = data.get('extract')
    validate = data.get('validate')
    api_msg_id = data.get('apiMsgId')
    up_func = data.get('upFunc')
    down_func = data.get('downFunc')
    method = data.get('method')
    module_id = data.get('moduleId')
    url = data.get('url').split('?')[0]
    skip = data.get('skip')
    status_url = data.get('choiceUrl')
    variable = data.get('variable')
    json_variable = data.get('jsonVariable')
    param = data.get('param')
    if not project_id:
        return jsonify({'msg': '项目不能为空', 'status': 0})
    if not module_id:
        return jsonify({'msg': '接口模块不能为空', 'status': 0})
    if not api_msg_name:
        return jsonify({'msg': '接口名称不能为空', 'status': 0})
    if method == -1:
        return jsonify({'msg': '请求方式不能为空', 'status': 0})
    if not url:
        return jsonify({'msg': '接口url不能为空', 'status': 0})
    if status_url == -1:
        if 'http' not in url:
            return jsonify({'msg': '基础url为空时，请补全api地址', 'status': 0})

    num = auto_num(data.get('num'), ApiMsg, module_id=module_id)

    if api_msg_id:
        old_data = ApiMsg.query.filter_by(id=api_msg_id).first()
        old_num = old_data.num
        if ApiMsg.query.filter_by(name=api_msg_name, module_id=module_id).first() and api_msg_name != old_data.name:
            return jsonify({'msg': '接口名字重复', 'status': 0})

        list_data = Module.query.filter_by(id=module_id).first().api_msg.all()
        num_sort(num, old_num, list_data, old_data)
        old_data.project_id = project_id
        old_data.name = api_msg_name
        old_data.validate = validate
        old_data.up_func = up_func
        old_data.down_func = down_func
        old_data.desc = desc
        old_data.status_url = status_url
        old_data.variable_type = variable_type
        old_data.method = method
        old_data.url = url
        old_data.skip = skip
        old_data.header = header
        old_data.variable = variable
        old_data.json_variable = json_variable
        old_data.param = param
        old_data.extract = extract
        old_data.module_id = module_id
        db.session.commit()
        return jsonify({'msg': '修改成功', 'status': 1, 'api_msg_id': api_msg_id, 'num': num})
    else:
        if ApiMsg.query.filter_by(name=api_msg_name, module_id=module_id).first():
            return jsonify({'msg': '接口名字重复', 'status': 0})
        else:
            new_cases = ApiMsg(name=api_msg_name,
                               num=num,
                               header=header,
                               up_func=up_func,
                               down_func=down_func,
                               url=url,
                               skip=skip,
                               desc=desc,
                               param=param,
                               method=method,
                               variable=variable,
                               validate=validate,
                               project_id=project_id,
                               module_id=module_id,
                               status_url=status_url,
                               variable_type=variable_type,
                               json_variable=json_variable,
                               extract=extract, )
            db.session.add(new_cases)
            db.session.commit()
            return jsonify({'msg': '新建成功', 'status': 1, 'api_msg_id': new_cases.id, 'num': new_cases.num})
def add_api_msg ( ) : data = request . json project_id = data . get ( 'projectId' ) api_msg_name = data . get ( 'apiMsgName' ) variable_type = data . get ( 'variableType' ) desc = data . get ( 'desc' ) header = data . get ( 'header' ) extract = data . get ( 'extract' ) validate = data . get ( 'validate' ) api_msg_id = data . get ( 'apiMsgId' ) up_func = data . get ( 'upFunc' ) down_func = data . get ( 'downFunc' ) method = data . get ( 'method' ) module_id = data . get ( 'moduleId' ) url = data . get ( 'url' ) . split ( '?' ) [ 0 ] skip = data . get ( 'skip' ) status_url = data . get ( 'choiceUrl' ) variable = data . get ( 'variable' ) json_variable = data . get ( 'jsonVariable' ) param = data . get ( 'param' ) if not project_id : return jsonify ( { 'msg' : '项目不能为空', 'status':  0 ) if not module_id : return jsonify ( { 'msg' : '接口模块不能为空', 'status': 0}) if not api_msg_name : return jsonify ( { 'msg' : '接口名称不能为空', 'status': 0}) if method == - 1 : return jsonify ( { 'msg' : '请求方式不能为空', 'status': 0}) if not url : return jsonify ( { 'msg' : '接口url不能为空', 'status':  0 ) if status_url == - 1 : if 'http' not in url : return jsonify ( { 'msg' : '基础url为空时，请补全api地址', 'status': 0}) num = auto_num ( data . get ( 'num' ) , ApiMsg , module_id = module_id ) if api_msg_id : old_data = ApiMsg . query . filter_by ( id = api_msg_id ) . first ( ) old_num = old_data . num if ApiMsg . query . filter_by ( name = api_msg_name , module_id = module_id ) . first ( ) and api_msg_name != old_data . name : return jsonify ( { 'msg' : '接口名字重复', 'status':  0 ) list_data = Module . query . filter_by ( id = module_id ) . first ( ) . api_msg . all ( ) num_sort ( num , old_num , list_data , old_data ) old_data . project_id = project_id old_data . name = api_msg_name old_data . validate = validate old_data . up_func = up_func old_data . down_func = down_func old_data . desc = desc old_data . status_url = status_url old_data . variable_type = variable_type old_data . method = method old_data . url = url old_data . skip = skip old_data . header = header old_data . variable = variable old_data . json_variable = json_variable old_data . param = param old_data . extract = extract old_data . module_id = module_id db . session . commit ( ) return jsonify ( { 'msg' : '修改成功', 'statu s : 1, 'ap i m s _id': api_ms g id, 'num': um}) else : if ApiMsg . query . filter_by ( name = api_msg_name , module_id = module_id ) . first ( ) : return jsonify ( { 'msg' : '接口名字重复', 'status':  0 ) else : new_cases = ApiMsg ( name = api_msg_name , num = num , header = header , up_func = up_func , down_func = down_func , url = url , skip = skip , desc = desc , param = param , method = method , variable = variable , validate = validate , project_id = project_id , module_id = module_id , status_url = status_url , variable_type = variable_type , json_variable = json_variable , extract = extract , ) db . session . add ( new_cases ) db . session . commit ( ) return jsonify ( { 'msg' : '新建成功', 'statu s : 1, 'ap i m s _id': new_ca s s.id, 'nu m ': ew_ca s s.num})