Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
add support for usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
spookybear0 committed Nov 6, 2020
1 parent f714c69 commit 9e0ad5c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ async def home(request:web.Request):

app.router.add_get("/", home)

@routes.get("/user/{userid}")
@routes.get("/user/{user}")
async def user(request:aiohttp.web.Request):
"""GET /api/user/{userid}
"""GET /api/user/{user}
Description:
Get a user by id
Example:
Expand All @@ -83,11 +83,19 @@ async def user(request:aiohttp.web.Request):
Return Type:
application/json
"""
userid = request.match_info["userid"]
user = request.match_info["user"]
try:
int(user)
is_int = True
except ValueError:
is_int = False
if not is_int:
user = user_helper.get_accountid_from_username(user)
try:
user = await user_helper.get_object(int(userid))
userobj = await user_helper.get_object(int(user))
except AssertionError:
return web.HTTPNotFound()
return json_resp(json.dumps(user.__dict__))
return web.HTTPNotFound("User not found")
return json_resp(json.dumps(userobj.__dict__))


app.add_routes(routes)

0 comments on commit 9e0ad5c

Please sign in to comment.