()
接口模块增加、编辑
接口模块增加、编辑
接口模块增加、编辑
def add_model():
    """ 接口模块增加、编辑 """
    data = request.json
    project_id = data.get('projectId')
    if not project_id:
        return jsonify({'msg': '请先创建项目', 'status': 0})
    name = data.get('name')
    if not name:
        return jsonify({'msg': '模块名称不能为空', 'status': 0})

    ids = data.get('id')
    num = auto_num(data.get('num'), Module, project_id=project_id)
    if ids:
        old_data = Module.get_first(id=ids)
        old_num = old_data.num
        list_data = Module.get_first(project_id=project_id).all()
        if Module.get_first(name=name, project_id=project_id) and name != old_data.name:
            return jsonify({'msg': '模块名字重复', 'status': 0})

        num_sort(num, old_num, list_data, old_data)
        old_data.name = name
        old_data.project_id = project_id
        db.session.commit()
        return jsonify({'msg': '修改成功', 'status': 1})
    else:
        if Module.get_first(name=name, project_id=project_id):
            return jsonify({'msg': '模块名字重复', 'status': 0})
        else:
            new_model = Module(name=name, project_id=project_id, num=num)
            db.session.add(new_model)
            db.session.commit()
            return jsonify({'msg': '新建成功', 'status': 1})
def add_model ( ) : data = request . json project_id = data . get ( 'projectId' ) if not project_id : return jsonify ( { 'msg' : '请先创建项目', 'status':  0 ) name = data . get ( 'name' ) if not name : return jsonify ( { 'msg' : '模块名称不能为空', 'status': 0}) ids = data . get ( 'id' ) num = auto_num ( data . get ( 'num' ) , Module , project_id = project_id ) if ids : old_data = Module . get_first ( id = ids ) old_num = old_data . num list_data = Module . get_first ( project_id = project_id ) . all ( ) if Module . get_first ( name = name , project_id = project_id ) and name != old_data . name : return jsonify ( { 'msg' : '模块名字重复', 'status':  0 ) num_sort ( num , old_num , list_data , old_data ) old_data . name = name old_data . project_id = project_id db . session . commit ( ) return jsonify ( { 'msg' : '修改成功', 'statu s : 1}) else : if Module . get_first ( name = name , project_id = project_id ) : return jsonify ( { 'msg' : '模块名字重复', 'status':  0 ) else : new_model = Module ( name = name , project_id = project_id , num = num ) db . session . add ( new_model ) db . session . commit ( ) return jsonify ( { 'msg' : '新建成功', 'statu s : 1})