From 522a985ef3afb259b6b9cfc3348061a9f415762b Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 25 Mar 2025 11:30:00 +0100 Subject: [PATCH] refactor(chalice): refactored pagination-query-string --- api/routers/subs/product_analytics.py | 23 +++++++++++++++-------- api/routers/subs/usability_tests.py | 20 +++++++++++--------- api/schemas/__init__.py | 1 + 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/api/routers/subs/product_analytics.py b/api/routers/subs/product_analytics.py index d8591b30d..a158c4d92 100644 --- a/api/routers/subs/product_analytics.py +++ b/api/routers/subs/product_analytics.py @@ -1,13 +1,26 @@ +from typing import Annotated + +from fastapi import Body, Depends, Query + import schemas from chalicelib.core.product_analytics import events, properties -from fastapi import Depends from or_dependencies import OR_context from routers.base import get_routers -from fastapi import Body, Depends, BackgroundTasks public_app, app, app_apikey = get_routers() +@app.get('/{projectId}/events/names', tags=["product_analytics"]) +def get_all_events(projectId: int, filter_query: Annotated[schemas.PaginatedSchema, Query()], + context: schemas.CurrentContext = Depends(OR_context)): + return { + "data": { + "events": events.get_events(project_id=projectId, page=filter_query), + "filters": {} + } + } + + @app.get('/{projectId}/properties/search', tags=["product_analytics"]) def get_event_properties(projectId: int, event_name: str = None, context: schemas.CurrentContext = Depends(OR_context)): @@ -16,12 +29,6 @@ def get_event_properties(projectId: int, event_name: str = None, return {"data": properties.get_properties(project_id=projectId, event_name=event_name)} -@app.get('/{projectId}/events/names', tags=["product_analytics"]) -def get_all_events(projectId: int, - context: schemas.CurrentContext = Depends(OR_context)): - return {"data": events.get_events(project_id=projectId)} - - @app.post('/{projectId}/events/search', tags=["product_analytics"]) def search_events(projectId: int, data: schemas.EventsSearchPayloadSchema = Body(...), context: schemas.CurrentContext = Depends(OR_context)): diff --git a/api/routers/subs/usability_tests.py b/api/routers/subs/usability_tests.py index 4db0e5817..3dc01c9b0 100644 --- a/api/routers/subs/usability_tests.py +++ b/api/routers/subs/usability_tests.py @@ -1,10 +1,12 @@ -from fastapi import Body, Depends +from typing import Annotated +from fastapi import Body, Depends, Query + +import schemas from chalicelib.core.usability_testing import service from chalicelib.core.usability_testing.schema import UTTestCreate, UTTestUpdate, UTTestSearch from or_dependencies import OR_context from routers.base import get_routers -from schemas import schemas public_app, app, app_apikey = get_routers() tags = ["usability-tests"] @@ -77,9 +79,8 @@ async def update_ut_test(projectId: int, test_id: int, test_update: UTTestUpdate @app.get('/{projectId}/usability-tests/{test_id}/sessions', tags=tags) -async def get_sessions(projectId: int, test_id: int, page: int = 1, limit: int = 10, - live: bool = False, - user_id: str = None): +async def get_sessions(projectId: int, test_id: int, filter_query: Annotated[schemas.PaginatedSchema, Query()], + live: bool = False, user_id: str = None): """ Get sessions related to a specific UT test. @@ -88,20 +89,21 @@ async def get_sessions(projectId: int, test_id: int, page: int = 1, limit: int = """ if live: - return service.ut_tests_sessions_live(projectId, test_id, page, limit) + return service.ut_tests_sessions_live(projectId, test_id, filter_query.page, filter_query.limit) else: - return service.ut_tests_sessions(projectId, test_id, page, limit, user_id, live) + return service.ut_tests_sessions(projectId, test_id, filter_query.page, filter_query.limit, user_id, live) @app.get('/{projectId}/usability-tests/{test_id}/responses/{task_id}', tags=tags) -async def get_responses(projectId: int, test_id: int, task_id: int, page: int = 1, limit: int = 10, query: str = None): +async def get_responses(projectId: int, test_id: int, task_id: int, + filter_query: Annotated[schemas.PaginatedSchema, Query()], query: str = None): """ Get responses related to a specific UT test. - **project_id**: The unique identifier of the project. - **test_id**: The unique identifier of the UT test. """ - return service.get_responses(test_id, task_id, page, limit, query) + return service.get_responses(test_id, task_id, filter_query.page, filter_query.limit, query) @app.get('/{projectId}/usability-tests/{test_id}/statistics', tags=tags) diff --git a/api/schemas/__init__.py b/api/schemas/__init__.py index 4bcc5be80..ffb620095 100644 --- a/api/schemas/__init__.py +++ b/api/schemas/__init__.py @@ -1,3 +1,4 @@ from .schemas import * from .product_analytics import * from . import overrides as _overrides +from .schemas import _PaginatedSchema as PaginatedSchema