Skip to content

Commit

Permalink
feat: shift to async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Vyvy-vi committed Aug 21, 2021
1 parent b5094b7 commit 6b1e1a2
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))



2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@app.get("/")
def index():
async def index():
body = "<h1>The Heptagram API</h1>"
return responses.HTMLResponse(content=body)

Expand Down
2 changes: 1 addition & 1 deletion src/routes/coinflip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/routes/diceroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/routes/jokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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]
Expand Down

0 comments on commit 6b1e1a2

Please sign in to comment.