diff --git a/src/apps/answers/crud/answers.py b/src/apps/answers/crud/answers.py index f497d461ac0..2749edfe484 100644 --- a/src/apps/answers/crud/answers.py +++ b/src/apps/answers/crud/answers.py @@ -949,7 +949,7 @@ async def get_respondents_by_applet_id_and_readiness_to_share_data( db_result = await self._execute(query) return db_result.scalars().all() - async def get_shareable_answers(self, applet_id: uuid.UUID): + async def get_shareable_answers(self, applet_id: uuid.UUID, page: int, limit: int): query: Query = ( select(AnswerSchema) .where( @@ -958,6 +958,7 @@ async def get_shareable_answers(self, applet_id: uuid.UUID): ) .order_by(AnswerSchema.created_at) ) + query = paging(query, page, limit) result = await self._execute(query) return result.scalars().all() diff --git a/src/apps/integrations/loris/api/applets.py b/src/apps/integrations/loris/api/applets.py index b3ff19127d5..1234931961e 100644 --- a/src/apps/integrations/loris/api/applets.py +++ b/src/apps/integrations/loris/api/applets.py @@ -8,6 +8,7 @@ from apps.authentication.deps import get_current_user from apps.integrations.loris.domain.domain import PublicListOfVisits, UploadableAnswersResponse, VisitsForUsers from apps.integrations.loris.service.loris import LorisIntegrationService +from apps.shared.query_params import BaseQueryParams, QueryParams, parse_query_params from apps.users.domain import User from apps.workspaces.service.check_access import CheckAccessService from infrastructure.database.deps import get_session @@ -51,11 +52,12 @@ async def visits_list( async def users_info_with_visits( applet_id: uuid.UUID, user: User = Depends(get_current_user), + query_params: QueryParams = Depends(parse_query_params(BaseQueryParams)), session=Depends(get_session), answer_session=Depends(get_answer_session), ) -> UploadableAnswersResponse: await CheckAccessService(session, user.id).check_answer_publishing_access(applet_id) loris_service = LorisIntegrationService(applet_id, session, user, answer_session=answer_session) # TODO move to worker - info, count = await loris_service.get_uploadable_answers() + info, count = await loris_service.get_uploadable_answers(query_params) return UploadableAnswersResponse(result=info, count=count) diff --git a/src/apps/integrations/loris/service/loris.py b/src/apps/integrations/loris/service/loris.py index 2679d9ffce3..3ad56b4d872 100644 --- a/src/apps/integrations/loris/service/loris.py +++ b/src/apps/integrations/loris/service/loris.py @@ -32,6 +32,7 @@ UserVisits, ) from apps.integrations.loris.errors import LorisServerError +from apps.shared.query_params import QueryParams from apps.subjects.crud import SubjectsCrud from apps.users.domain import User from apps.workspaces.crud.user_applet_access import UserAppletAccessCRUD @@ -792,7 +793,7 @@ async def get_information_about_users_and_visits(self): return result - async def get_uploadable_answers(self) -> tuple[UploadableAnswersData, int]: + async def get_uploadable_answers(self, filters: QueryParams) -> tuple[UploadableAnswersData, int]: """ This method is build to replace `get_information_about_users_and_visits` providing data in another structure """ @@ -801,8 +802,7 @@ async def get_uploadable_answers(self) -> tuple[UploadableAnswersData, int]: uploaded_answers, applet_visits, answers = await asyncio.gather( self._get_existing_answers_from_loris(str(self.applet_id)), self.get_visits_for_applet(), - # todo pagination - AnswersCRUD(self.answer_session).get_shareable_answers(applet_id=self.applet_id), + AnswersCRUD(self.answer_session).get_shareable_answers(self.applet_id, filters.page, filters.limit), ) uploaded_answer_ids = set(uploaded_answers)