From 76ce9f3c47361b2656e82bc69633c45ba8bf9121 Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Thu, 23 Oct 2025 16:52:32 -0500 Subject: [PATCH] CLAUDE: Add sorting and pagination to pitching totals endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add sort parameter support (player, team, wpa, repri, pa, newest/oldest) - Add pagination with page_num and limit - Ensure minimum limit of 1 to prevent errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- app/routers_v3/stratplay.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/app/routers_v3/stratplay.py b/app/routers_v3/stratplay.py index 11eb2cd..fadcf6f 100644 --- a/app/routers_v3/stratplay.py +++ b/app/routers_v3/stratplay.py @@ -795,6 +795,35 @@ async def get_pitching_totals( # Group by the fields if pitch_select_fields: pitch_plays = pitch_plays.group_by(*pitch_select_fields) + + # Apply sorting + if sort is not None: + if sort == 'player': + pitch_plays = pitch_plays.order_by(StratPlay.pitcher) + elif sort == 'team': + pitch_plays = pitch_plays.order_by(StratPlay.pitcher_team) + elif sort == 'wpa-desc': + pitch_plays = pitch_plays.order_by(SQL('sum_wpa').desc()) + elif sort == 'wpa-asc': + pitch_plays = pitch_plays.order_by(SQL('sum_wpa').asc()) + elif sort == 'repri-desc': + pitch_plays = pitch_plays.order_by(SQL('sum_repri').desc()) + elif sort == 'repri-asc': + pitch_plays = pitch_plays.order_by(SQL('sum_repri').asc()) + elif sort == 'pa-desc': + pitch_plays = pitch_plays.order_by(SQL('sum_pa').desc()) + elif sort == 'pa-asc': + pitch_plays = pitch_plays.order_by(SQL('sum_pa').asc()) + elif sort == 'newest': + if group_by in ['playergame', 'teamgame']: + pitch_plays = pitch_plays.order_by(StratPlay.game.desc()) + elif sort == 'oldest': + if group_by in ['playergame', 'teamgame']: + pitch_plays = pitch_plays.order_by(StratPlay.game.asc()) + + if limit < 1: + limit = 1 + pitch_plays = pitch_plays.paginate(page_num, limit) # Execute the Peewee query return_stats = {