Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added pagination for endpoint that return answers for loris (M2-7656) #1571

Open
wants to merge 1 commit into
base: loris-integration-phase-2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/apps/answers/crud/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
4 changes: 3 additions & 1 deletion src/apps/integrations/loris/api/applets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions src/apps/integrations/loris/service/loris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
"""
Expand All @@ -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)
Expand Down
Loading