Skip to content

Commit

Permalink
refactor(vlr_router.py): use Query parameters for VLR_stats endpoint …
Browse files Browse the repository at this point in the history
…to improve API clarity and usability

fix(vlr_router.py): correct import order and add missing import for Query from fastapi
  • Loading branch information
axsddlr committed Sep 16, 2024
1 parent 9b80a1c commit becfe4b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions routers/vlr_router.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from fastapi import APIRouter, Request
from api.scrape import Vlr
from fastapi import APIRouter, Query, Request
from slowapi import Limiter
from slowapi.util import get_remote_address

from api.scrape import Vlr

router = APIRouter()
limiter = Limiter(key_func=get_remote_address)
vlr = Vlr()
Expand All @@ -14,10 +15,16 @@ async def VLR_news(request: Request):
return vlr.vlr_news()


@router.get("/stats/{region}/{timespan}")
@router.get("/stats")
@limiter.limit("250/minute")
async def VLR_stats(region, timespan, request: Request):
async def VLR_stats(
request: Request,
region: str = Query(..., description="Region shortname"),
timespan: str = Query(..., description="Timespan (30, 60, 90, or all)"),
):
"""
Get VLR stats with query parameters.
region shortnames:\n
"na": "north-america",\n
"eu": "europe",\n
Expand All @@ -26,14 +33,11 @@ async def VLR_stats(region, timespan, request: Request):
"jp": "japan",\n
"oce": "oceania",\n
"mn": "mena"\n
timespan:\n
"30": 30 days,\n
"60": 60 days,\n
"90": 90 days,\n
"all": All time\n"
"""
return vlr.vlr_stats(region, timespan)
return vlr.vlr_stats(
region,
timespan,
)


@router.get("/rankings/{region}")
Expand Down

0 comments on commit becfe4b

Please sign in to comment.