diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2e726..8e7f9fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,3 @@ * diceroll and coinflip routes ([dc8e66c](https://github.com/Heptagram-Bot/api/commit/dc8e66cda8c8c28a5f99c50520424d0822e0277a)) * Query constraints for routes ([ca97955](https://github.com/Heptagram-Bot/api/commit/ca979556027355e90c4f58d5bec4fe584c05069b)) * set up docker config ([efbd608](https://github.com/Heptagram-Bot/api/commit/efbd608d090e6ac7a65357d0a3ba4747a7afb1d5)) - - - diff --git a/src/main.py b/src/main.py index cf9582f..a4e6a45 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ @app.get("/") -def index(): +async def index(): body = "

The Heptagram API

" return responses.HTMLResponse(content=body) diff --git a/src/routes/coinflip.py b/src/routes/coinflip.py index f8ca2a2..867b7fa 100644 --- a/src/routes/coinflip.py +++ b/src/routes/coinflip.py @@ -6,7 +6,7 @@ @router.get("/coinflip") -def flip_coin(num: int = Query(1, ge=1, le=10000)): +async def flip_coin(num: int = Query(1, ge=1, le=10000)): return { "task": f"coinflip x {num}", "result": random.choices(["Heads", "Tails"], k=num), diff --git a/src/routes/diceroll.py b/src/routes/diceroll.py index a878375..f400e3a 100644 --- a/src/routes/diceroll.py +++ b/src/routes/diceroll.py @@ -6,7 +6,7 @@ @router.get("/diceroll") -def roll_dice( +async def roll_dice( num: int = Query(1, ge=1, le=10000), sides: int = Query(6, ge=3, le=10000) ): return { diff --git a/src/routes/jokes.py b/src/routes/jokes.py index 836297f..de033c2 100644 --- a/src/routes/jokes.py +++ b/src/routes/jokes.py @@ -8,7 +8,7 @@ @router.get("/jokes/all") -def all_jokes(): +async def all_jokes(): return { "jokes": [ {"id": joke_id, "joke": jokes[joke_id]} for joke_id in range(len(jokes)) @@ -17,12 +17,12 @@ def all_jokes(): @router.get("/jokes/{joke_id}") -def jokes_by_id(joke_id: int = Path(..., ge=0, lt=len(jokes))): +async def jokes_by_id(joke_id: int = Path(..., ge=0, lt=len(jokes))): return {"joke": jokes[joke_id], "id": joke_id} @router.get("/jokes") -def get_jokes(num: int = Query(1, ge=1, lt=len(jokes))): +async def get_jokes(num: int = Query(1, ge=1, lt=len(jokes))): random_ids = sorted(random.sample(range(len(jokes)), num)) return { "jokes": [{"id": joke_id, "joke": jokes[joke_id]} for joke_id in random_ids]