CLAUDE: Add sorting and pagination to pitching totals endpoint
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
e75c1fbc7d
commit
76ce9f3c47
@ -796,6 +796,35 @@ async def get_pitching_totals(
|
|||||||
if pitch_select_fields:
|
if pitch_select_fields:
|
||||||
pitch_plays = pitch_plays.group_by(*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
|
# Execute the Peewee query
|
||||||
return_stats = {
|
return_stats = {
|
||||||
'count': 0,
|
'count': 0,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user