Skip to content

Commit a04c2ef

Browse files
committed
feat: add pagination support for paragraph retrieval in Paragraph API
1 parent 36da813 commit a04c2ef

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

apps/knowledge/api/paragraph.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,52 @@ def get_parameters():
206206

207207
class AssociationAPI(UnAssociationAPI):
208208
pass
209+
210+
211+
class ParagraphPageAPI(APIMixin):
212+
@staticmethod
213+
def get_parameters():
214+
return [
215+
OpenApiParameter(
216+
name="workspace_id",
217+
description="工作空间id",
218+
type=OpenApiTypes.STR,
219+
location='path',
220+
required=True,
221+
),
222+
OpenApiParameter(
223+
name="knowledge_id",
224+
description="知识库id",
225+
type=OpenApiTypes.STR,
226+
location='path',
227+
required=True,
228+
),
229+
OpenApiParameter(
230+
name="document_id",
231+
description="文档id",
232+
type=OpenApiTypes.STR,
233+
location='path',
234+
required=True,
235+
),
236+
OpenApiParameter(
237+
name="paragraph_id",
238+
description="段落id",
239+
type=OpenApiTypes.STR,
240+
location='path',
241+
required=True,
242+
),
243+
OpenApiParameter(
244+
name="current_page",
245+
description="当前页",
246+
type=OpenApiTypes.INT,
247+
location='path',
248+
required=True,
249+
),
250+
OpenApiParameter(
251+
name="page_size",
252+
description="每页大小",
253+
type=OpenApiTypes.INT,
254+
location='path',
255+
required=True,
256+
),
257+
]

apps/knowledge/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/batch', views.ParagraphView.Batch.as_view()),
2626
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>', views.ParagraphView.Operate.as_view()),
2727
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>/problem', views.ParagraphView.Problem.as_view()),
28+
path( 'workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<int:current_page>/<int:page_size>', views.ParagraphView.Page.as_view()),
2829
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>/problem/<str:problem_id>/association', views.ParagraphView.Association.as_view()),
2930
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>/problem/<str:problem_id>/unassociation', views.ParagraphView.UnAssociation.as_view()),
3031
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<int:current_page>/<int:page_sige>', views.DocumentView.Page.as_view()),

apps/knowledge/views/paragraph.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from common.result import result
1010
from common.utils.common import query_params_to_single_dict
1111
from knowledge.api.paragraph import ParagraphReadAPI, ParagraphCreateAPI, ParagraphBatchDeleteAPI, ParagraphEditAPI, \
12-
ParagraphGetAPI, ProblemCreateAPI, UnAssociationAPI, AssociationAPI
12+
ParagraphGetAPI, ProblemCreateAPI, UnAssociationAPI, AssociationAPI, ParagraphPageAPI
1313
from knowledge.serializers.paragraph import ParagraphSerializers
1414

1515

@@ -232,3 +232,29 @@ def get(self, request: Request,
232232
'problem_id': problem_id
233233
}
234234
).association())
235+
236+
class Page(APIView):
237+
authentication_classes = [TokenAuth]
238+
239+
@extend_schema(
240+
methods=['GET'],
241+
summary=_('Get paragraph list by pagination'),
242+
description=_('Get paragraph list by pagination'),
243+
operation_id=_('Get paragraph list by pagination'),
244+
parameters=ParagraphPageAPI.get_parameters(),
245+
responses=ParagraphPageAPI.get_response(),
246+
tags=[_('Knowledge Base/Documentation/Paragraph')]
247+
)
248+
@has_permissions(PermissionConstants.DOCUMENT_EDIT.get_workspace_permission())
249+
def get(self, request: Request,
250+
workspace_id: str, knowledge_id: str, document_id: str, current_page: int, page_size: int):
251+
d = ParagraphSerializers.Query(
252+
data={
253+
**query_params_to_single_dict(request.query_params),
254+
'workspace_id': workspace_id,
255+
'knowledge_id': knowledge_id,
256+
'document_id': document_id
257+
}
258+
)
259+
d.is_valid(raise_exception=True)
260+
return result.success(d.page(current_page, page_size))

0 commit comments

Comments
 (0)