feat: add ProblemParagraphAPI for retrieving associated paragraphs and update routing

This commit is contained in:
CaptainB 2025-05-07 17:37:34 +08:00
parent 6cdd5b4508
commit a09d0d5171
3 changed files with 29 additions and 2 deletions

View File

@ -121,7 +121,11 @@ class ProblemDeleteAPI(APIMixin):
return DefaultResultSerializer
class ProblemEditAPI(ProblemReadAPI):
class ProblemEditAPI(ProblemDeleteAPI):
@staticmethod
def get_request():
return ProblemEditSerializer
class ProblemParagraphAPI(ProblemDeleteAPI):
pass

View File

@ -34,6 +34,7 @@ urlpatterns = [
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/<str:problem_id>/paragraph', views.ProblemView.Paragraph.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()),

View File

@ -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, ProblemDeleteAPI, ProblemEditAPI
ProblemPageAPI, ProblemDeleteAPI, ProblemEditAPI, ProblemParagraphAPI
from knowledge.serializers.problem import ProblemSerializers
@ -53,6 +53,28 @@ class ProblemView(APIView):
data={'workspace_id': workspace_id, 'knowledge_id': knowledge_id, 'problem_list': request.data}
).batch())
class Paragraph(APIView):
authentication_classes = [TokenAuth]
@extend_schema(
summary=_('Get a list of associated paragraphs'),
description=_('Get a list of associated paragraphs'),
operation_id=_('Get a list of associated paragraphs'),
parameters=ProblemParagraphAPI.get_parameters(),
responses=ProblemParagraphAPI.get_response(),
tags=[_('Knowledge Base/Documentation/Paragraph/Question')]
)
@has_permissions(PermissionConstants.DOCUMENT_EDIT.get_workspace_permission())
def get(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
}
).list_paragraph())
class BatchAssociation(APIView):
authentication_classes = [TokenAuth]