mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-30 01:32:49 +00:00
feat: implement Problem API for delete and modify operations with new Operate endpoint
This commit is contained in:
parent
a6c74024b0
commit
6cdd5b4508
|
|
@ -4,7 +4,7 @@ from drf_spectacular.utils import OpenApiParameter
|
|||
from common.mixins.api_mixin import APIMixin
|
||||
from common.result import DefaultResultSerializer
|
||||
from knowledge.serializers.problem import ProblemBatchSerializer, \
|
||||
ProblemBatchDeleteSerializer, BatchAssociation
|
||||
ProblemBatchDeleteSerializer, BatchAssociation, ProblemEditSerializer
|
||||
|
||||
|
||||
class ProblemReadAPI(APIMixin):
|
||||
|
|
@ -87,3 +87,41 @@ class ProblemPageAPI(APIMixin):
|
|||
@staticmethod
|
||||
def get_response():
|
||||
return DefaultResultSerializer
|
||||
|
||||
|
||||
class ProblemDeleteAPI(APIMixin):
|
||||
@staticmethod
|
||||
def get_parameters():
|
||||
return [
|
||||
OpenApiParameter(
|
||||
name="workspace_id",
|
||||
description="工作空间id",
|
||||
type=OpenApiTypes.STR,
|
||||
location='path',
|
||||
required=True,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="knowledge_id",
|
||||
description="知识库id",
|
||||
type=OpenApiTypes.STR,
|
||||
location='path',
|
||||
required=True,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="problem_id",
|
||||
description="问题id",
|
||||
type=OpenApiTypes.STR,
|
||||
location='path',
|
||||
required=True,
|
||||
)
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def get_response():
|
||||
return DefaultResultSerializer
|
||||
|
||||
|
||||
class ProblemEditAPI(ProblemReadAPI):
|
||||
@staticmethod
|
||||
def get_request():
|
||||
return ProblemEditSerializer
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ class ProblemInstanceSerializer(serializers.Serializer):
|
|||
id = serializers.CharField(required=False, label=_('problem id'))
|
||||
content = serializers.CharField(required=True, max_length=256, label=_('content'))
|
||||
|
||||
class ProblemEditSerializer(serializers.Serializer):
|
||||
content = serializers.CharField(required=True, max_length=256, label=_('content'))
|
||||
|
||||
|
||||
class ProblemMappingSerializer(serializers.Serializer):
|
||||
paragraph_id = serializers.UUIDField(required=True, label=_('paragraph id'))
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ urlpatterns = [
|
|||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/problem', views.ProblemView.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/problem/batch_delete', views.ProblemView.BatchDelete.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/problem/batch_association', views.ProblemView.BatchAssociation.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/problem/<str:problem_id>', views.ProblemView.Operate.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/problem/<int:current_page>/<int:page_size>', views.ProblemView.Page.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<int:current_page>/<int:page_size>', views.DocumentView.Page.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<int:current_page>/<int:page_size>', views.KnowledgeView.Page.as_view()),
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from common.constants.permission_constants import PermissionConstants
|
|||
from common.result import result
|
||||
from common.utils.common import query_params_to_single_dict
|
||||
from knowledge.api.problem import ProblemReadAPI, ProblemBatchCreateAPI, BatchAssociationAPI, BatchDeleteAPI, \
|
||||
ProblemPageAPI
|
||||
ProblemPageAPI, ProblemDeleteAPI, ProblemEditAPI
|
||||
from knowledge.serializers.problem import ProblemSerializers
|
||||
|
||||
|
||||
|
|
@ -90,6 +90,48 @@ class ProblemView(APIView):
|
|||
data={'knowledge_id': knowledge_id, 'workspace_id': workspace_id}
|
||||
).delete(request.data))
|
||||
|
||||
class Operate(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
@extend_schema(
|
||||
methods=['DELETE'],
|
||||
summary=_('Delete question'),
|
||||
description=_('Delete question'),
|
||||
operation_id=_('Delete question'),
|
||||
parameters=ProblemDeleteAPI.get_parameters(),
|
||||
responses=ProblemDeleteAPI.get_response(),
|
||||
tags=[_('Knowledge Base/Documentation/Paragraph/Question')]
|
||||
)
|
||||
def delete(self, request: Request, workspace_id: str, knowledge_id: str, problem_id: str):
|
||||
return result.success(ProblemSerializers.Operate(
|
||||
data={
|
||||
**query_params_to_single_dict(request.query_params),
|
||||
'workspace_id': workspace_id,
|
||||
'knowledge_id': knowledge_id,
|
||||
'problem_id': problem_id
|
||||
}
|
||||
).delete())
|
||||
|
||||
@extend_schema(
|
||||
methods=['PUT'],
|
||||
summary=_('Modify question'),
|
||||
description=_('Modify question'),
|
||||
operation_id=_('Modify question'),
|
||||
parameters=ProblemEditAPI.get_parameters(),
|
||||
request=ProblemEditAPI.get_request(),
|
||||
responses=ProblemEditAPI.get_response(),
|
||||
tags=[_('Knowledge Base/Documentation/Paragraph/Question')]
|
||||
)
|
||||
def put(self, request: Request, workspace_id: str, knowledge_id: str, problem_id: str):
|
||||
return result.success(ProblemSerializers.Operate(
|
||||
data={
|
||||
**query_params_to_single_dict(request.query_params),
|
||||
'workspace_id': workspace_id,
|
||||
'knowledge_id': knowledge_id,
|
||||
'problem_id': problem_id
|
||||
}
|
||||
).edit(request.data))
|
||||
|
||||
class Page(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue