Skip to content

Commit

Permalink
feat: 函数库删除接口
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Aug 16, 2024
1 parent 0d59ab2 commit 690e6f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 690e6f6

Please sign in to comment.