mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: add pagination support for paragraph retrieval in Paragraph API
This commit is contained in:
parent
36da813eea
commit
a04c2efa41
|
|
@ -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,
|
||||
),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ urlpatterns = [
|
|||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/batch', views.ParagraphView.Batch.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>', views.ParagraphView.Operate.as_view()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<str:document_id>/paragraph/<str:paragraph_id>/problem', views.ParagraphView.Problem.as_view()),
|
||||
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()),
|
||||
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()),
|
||||
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()),
|
||||
path('workspace/<str:workspace_id>/knowledge/<str:knowledge_id>/document/<int:current_page>/<int:page_sige>', views.DocumentView.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.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))
|
||||
|
|
|
|||
Loading…
Reference in New Issue