diff --git a/Modules/Indicators/Tags/TagsImpl.py b/Modules/Indicators/Tags/TagsImpl.py index bbc9305..6b7beb8 100644 --- a/Modules/Indicators/Tags/TagsImpl.py +++ b/Modules/Indicators/Tags/TagsImpl.py @@ -96,3 +96,37 @@ class TagsImpl(object): ) return '关联成功' + + @staticmethod + def associate_api(**kwargs): + """关联接口""" + data = kwargs['data'] + + obj = TagObj.AssociateApi() + obj.api_id = data['api_id'] + obj.api_name = data['api_name'] + + for item in data['tags_id']: + DB_TEST.update_single_data_by_add( + '模型数据', + '标签数据', + {'标签ID': item}, + {"关联接口": obj.fields_toggle()} + ) + + return '关联成功' + + @staticmethod + def cancel_associate_api(**kwargs): + """取消关联接口""" + tag_id = kwargs['tag_id'] + api_id = kwargs['api_id'] + + DB_TEST.update_single_data_by_pull( + '模型数据', + '标签数据', + {'标签ID': tag_id}, + {"关联接口": {"接口ID": api_id}} + ) + + return '取消关联成功' diff --git a/Modules/Indicators/Tags/TagsObj.py b/Modules/Indicators/Tags/TagsObj.py index f851fca..4beb223 100644 --- a/Modules/Indicators/Tags/TagsObj.py +++ b/Modules/Indicators/Tags/TagsObj.py @@ -77,10 +77,21 @@ class TagObj(SpecObject): "func_name": "函数名称" } + class AssociateApi(SpecObject): + """关联接口""" + api_id = ValidateAttr(field='api_id', type=str) + api_name = ValidateAttr(field='api_name', type=str) + + fields_map = { + "api_id": "接口ID", + "api_name": "接口名称" + } + tag_id = ValidateAttr(field='tag_id', type=str) tag_field = ValidateAttr(field='tag_field', type=str) tag_category = ValidateAttr(field='tag_category', type=str) associate_func = ValidateAttr(field='associate_func', instance_list=AssociateFunc) + associate_api = ValidateAttr(field='associate_api', instance_list=AssociateApi) create_date = ValidateAttr(field='create_date', func=Validate.date_format) fields_map = { @@ -88,5 +99,6 @@ class TagObj(SpecObject): "tag_field": "标签名称", "tag_category": "标签类别", "associate_func": "关联函数", + "associate_api": "关联接口", "create_date": "创建日期" } diff --git a/Modules/Indicators/Tags/TagsRoutes.py b/Modules/Indicators/Tags/TagsRoutes.py index 07acab4..e708f89 100644 --- a/Modules/Indicators/Tags/TagsRoutes.py +++ b/Modules/Indicators/Tags/TagsRoutes.py @@ -68,3 +68,32 @@ def associate_func_route(): except APIReturnError as e: return {"info": e.__str__()}, e.status_code + + +@tags_route.route('/associate_api', methods=['POST']) +def associate_api_route(): + """关联接口""" + try: + RouteParamsCheck(request.json, ["tags_id", "api_id", "api_name"]).required() + data = request.json + impl = TagsImpl() + result = impl.associate_api(data=data) + return {"info": "关联接口", "result": result}, 200 + + except APIReturnError as e: + return {"info": e.__str__()}, e.status_code + + +@tags_route.route('/cancel_associate_api', methods=['GET']) +def cancel_associate_api_route(): + """取消关联接口""" + try: + RouteParamsCheck(request.args, ["tag_id", "api_id"]).required() + tag_id = request.args['tag_id'] + api_id = request.args['api_id'] + impl = TagsImpl() + result = impl.cancel_associate_api(tag_id=tag_id, api_id=api_id) + return {"info": "关联接口", "result": result}, 200 + + except APIReturnError as e: + return {"info": e.__str__()}, e.status_code