diff --git a/apps/knowledge/api/paragraph.py b/apps/knowledge/api/paragraph.py index f18098cd0..1e3f7f28b 100644 --- a/apps/knowledge/api/paragraph.py +++ b/apps/knowledge/api/paragraph.py @@ -206,3 +206,52 @@ class UnAssociationAPI(APIMixin): class AssociationAPI(UnAssociationAPI): pass + + +class ParagraphPageAPI(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="document_id", + description="文档id", + type=OpenApiTypes.STR, + location='path', + required=True, + ), + OpenApiParameter( + name="paragraph_id", + description="段落id", + type=OpenApiTypes.STR, + location='path', + required=True, + ), + OpenApiParameter( + name="current_page", + description="当前页", + type=OpenApiTypes.INT, + location='path', + required=True, + ), + OpenApiParameter( + name="page_size", + description="每页大小", + type=OpenApiTypes.INT, + location='path', + required=True, + ), + ] diff --git a/apps/knowledge/urls.py b/apps/knowledge/urls.py index d2d62ccaa..5ff968dc7 100644 --- a/apps/knowledge/urls.py +++ b/apps/knowledge/urls.py @@ -25,6 +25,7 @@ urlpatterns = [ path('workspace//knowledge//document//paragraph/batch', views.ParagraphView.Batch.as_view()), path('workspace//knowledge//document//paragraph/', views.ParagraphView.Operate.as_view()), path('workspace//knowledge//document//paragraph//problem', views.ParagraphView.Problem.as_view()), + path( 'workspace//knowledge//document//paragraph//', views.ParagraphView.Page.as_view()), path('workspace//knowledge//document//paragraph//problem//association', views.ParagraphView.Association.as_view()), path('workspace//knowledge//document//paragraph//problem//unassociation', views.ParagraphView.UnAssociation.as_view()), path('workspace//knowledge//document//', views.DocumentView.Page.as_view()), diff --git a/apps/knowledge/views/paragraph.py b/apps/knowledge/views/paragraph.py index b6b75ef7b..3ceaa4fd6 100644 --- a/apps/knowledge/views/paragraph.py +++ b/apps/knowledge/views/paragraph.py @@ -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.paragraph import ParagraphReadAPI, ParagraphCreateAPI, ParagraphBatchDeleteAPI, ParagraphEditAPI, \ - ParagraphGetAPI, ProblemCreateAPI, UnAssociationAPI, AssociationAPI + ParagraphGetAPI, ProblemCreateAPI, UnAssociationAPI, AssociationAPI, ParagraphPageAPI from knowledge.serializers.paragraph import ParagraphSerializers @@ -232,3 +232,29 @@ class ParagraphView(APIView): 'problem_id': problem_id } ).association()) + + class Page(APIView): + authentication_classes = [TokenAuth] + + @extend_schema( + methods=['GET'], + summary=_('Get paragraph list by pagination'), + description=_('Get paragraph list by pagination'), + operation_id=_('Get paragraph list by pagination'), + parameters=ParagraphPageAPI.get_parameters(), + responses=ParagraphPageAPI.get_response(), + tags=[_('Knowledge Base/Documentation/Paragraph')] + ) + @has_permissions(PermissionConstants.DOCUMENT_EDIT.get_workspace_permission()) + def get(self, request: Request, + workspace_id: str, knowledge_id: str, document_id: str, current_page: int, page_size: int): + d = ParagraphSerializers.Query( + data={ + **query_params_to_single_dict(request.query_params), + 'workspace_id': workspace_id, + 'knowledge_id': knowledge_id, + 'document_id': document_id + } + ) + d.is_valid(raise_exception=True) + return result.success(d.page(current_page, page_size))