From 6034b4f1732370a71df9fce81e819f49d58246fd Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Tue, 24 Mar 2026 01:03:12 -0500 Subject: [PATCH] feat: add limit/pagination to batstats endpoint (#133) Closes #133 Co-Authored-By: Claude Sonnet 4.6 --- app/routers_v2/batstats.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/routers_v2/batstats.py b/app/routers_v2/batstats.py index 95c9db9..c60949b 100644 --- a/app/routers_v2/batstats.py +++ b/app/routers_v2/batstats.py @@ -66,7 +66,8 @@ class BatStatReturnList(pydantic.BaseModel): @router.get('', response_model=BatStatReturnList) async def get_batstats( card_id: int = None, player_id: int = None, team_id: int = None, vs_team_id: int = None, week: int = None, - season: int = None, week_start: int = None, week_end: int = None, created: int = None, csv: bool = None): + season: int = None, week_start: int = None, week_end: int = None, created: int = None, csv: bool = None, + limit: Optional[int] = 100): all_stats = BattingStat.select().join(Card).join(Player).order_by(BattingStat.id) if season is not None: @@ -98,6 +99,9 @@ async def get_batstats( # db.close() # raise HTTPException(status_code=404, detail=f'No batting stats found') + limit = max(0, min(limit, 500)) + all_stats = all_stats.limit(limit) + if csv: data_list = [['id', 'card_id', 'player_id', 'cardset', 'team', 'vs_team', 'pos', 'pa', 'ab', 'run', 'hit', 'rbi', 'double', 'triple', 'hr', 'bb', 'so', 'hbp', 'sac', 'ibb', 'gidp', 'sb', 'cs', 'bphr', 'bpfo', 'bp1b',