Merge branch 'main' into issue/138-feat-add-limit-pagination-to-stratgame-games-endpo
This commit is contained in:
commit
2486d85112
@ -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',
|
||||
|
||||
@ -4,7 +4,7 @@ from typing import Optional
|
||||
import logging
|
||||
import pydantic
|
||||
|
||||
from ..db_engine import ScoutClaim, ScoutOpportunity, model_to_dict
|
||||
from ..db_engine import ScoutClaim, model_to_dict
|
||||
from ..dependencies import oauth2_scheme, valid_token
|
||||
|
||||
router = APIRouter(prefix="/api/v2/scout_claims", tags=["scout_claims"])
|
||||
@ -18,7 +18,9 @@ class ScoutClaimModel(pydantic.BaseModel):
|
||||
|
||||
@router.get("")
|
||||
async def get_scout_claims(
|
||||
scout_opportunity_id: Optional[int] = None, claimed_by_team_id: Optional[int] = None
|
||||
scout_opportunity_id: Optional[int] = None,
|
||||
claimed_by_team_id: Optional[int] = None,
|
||||
limit: Optional[int] = 100,
|
||||
):
|
||||
|
||||
query = ScoutClaim.select().order_by(ScoutClaim.id)
|
||||
@ -28,6 +30,10 @@ async def get_scout_claims(
|
||||
if claimed_by_team_id is not None:
|
||||
query = query.where(ScoutClaim.claimed_by_team_id == claimed_by_team_id)
|
||||
|
||||
if limit is not None:
|
||||
limit = max(0, min(limit, 500))
|
||||
query = query.limit(limit)
|
||||
|
||||
results = [model_to_dict(x, recurse=False) for x in query]
|
||||
return {"count": len(results), "results": results}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user