Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 函数库删除接口 #985

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/function_lib/serializers/function_lib_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ def is_valid(self, *, raise_exception=False):
if not QuerySet(FunctionLib).filter(id=self.data.get('id'), user_id=self.data.get('user_id')).exists():
raise AppApiException(500, '函数不存在')

def delete(self, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
QuerySet(FunctionLib).filter(id=self.data.get('id')).delete()
return True

def edit(self, instance, with_valid=True):
if with_valid:
self.is_valid(raise_exception=True)
Expand Down
9 changes: 9 additions & 0 deletions apps/function_lib/views/function_lib_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def put(self, request: Request, function_lib_id: str):
FunctionLibSerializer.Operate(data={'user_id': request.user.id, 'id': function_lib_id}).edit(
request.data))

@action(methods=['DELETE'], detail=False)
@swagger_auto_schema(operation_summary="删除函数",
operation_id="删除函数",
tags=['函数库'])
@has_permissions(RoleConstants.ADMIN, RoleConstants.USER)
def delete(self, request: Request, function_lib_id: str):
return result.success(
FunctionLibSerializer.Operate(data={'user_id': request.user.id, 'id': function_lib_id}).delete())

class Page(APIView):
authentication_classes = [TokenAuth]

Expand Down
Loading