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

[Backend] add limit prams to possiton history endpoint #523

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Changes from 2 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
21 changes: 13 additions & 8 deletions web_app/api/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Optional
from uuid import UUID

from fastapi import APIRouter, HTTPException, Request
from fastapi import APIRouter, HTTPException, Query, Request

from web_app.api.serializers.position import (
AddPositionDepositData,
Expand Down Expand Up @@ -315,11 +315,17 @@ async def add_extra_deposit(position_id: UUID, data: AddPositionDepositData):
summary="Get all positions for a user",
response_description="Returns paginated list of positions for the given wallet ID",
)
async def get_user_positions(wallet_id: str, start: Optional[int] = None) -> list:
async def get_user_positions(
wallet_id: str,
start: Optional[int] = None,
limit: int = Query(PAGINATION_STEP, ge=1, le=100),
) -> list:
"""
Get all positions for a specific user by their wallet ID.
:param wallet_id: The wallet ID of the user
:param start: Optional starting index for pagination (0-based). If not provided, defaults to 0
:param limit: Optional number of records to return. min 1, max 100.
If not provided, defaults to PAGINATION_STEP
:return: UserPositionsListResponse containing paginated list of positions
:raises: HTTPException: If wallet ID is empty or invalid
"""
Expand All @@ -329,7 +335,7 @@ async def get_user_positions(wallet_id: str, start: Optional[int] = None) -> lis
start_index = max(0, start) if start is not None else 0

positions = position_db_connector.get_all_positions_by_wallet_id(
wallet_id, start_index, PAGINATION_STEP
wallet_id, start_index, limit
)
return positions

Expand All @@ -348,8 +354,7 @@ async def get_list_of_deposited_tokens(position_id: UUID):
:return Dict containing main position and extra positions
"""
main_position = position_db_connector.get_position_by_id(position_id)
extra_deposits = position_db_connector.get_extra_deposits_by_position_id(position_id)
return {
"main": main_position,
"extra_deposits": extra_deposits
}
extra_deposits = position_db_connector.get_extra_deposits_by_position_id(
position_id
)
return {"main": main_position, "extra_deposits": extra_deposits}
Loading