1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 12:04:20 +00:00
royalnet/royalpack/stars/api_user_get.py

22 lines
754 B
Python
Raw Normal View History

2019-11-11 08:56:08 +00:00
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation import *
2019-11-11 08:56:08 +00:00
from royalnet.utils import *
from royalnet.backpack.tables import *
2019-11-11 08:56:08 +00:00
class ApiUserGetStar(PageStar):
path = "/api/user/get/{uid_str}"
async def page(self, request: Request) -> JSONResponse:
uid_str = request.path_params.get("uid_str", "")
try:
uid = int(uid_str)
except (ValueError, TypeError):
return shoot(400, "Invalid uid")
2019-11-11 08:56:08 +00:00
async with self.alchemy.session_acm() as session:
user: User = await asyncify(session.query(self.alchemy.get(User)).get, uid)
2019-11-11 08:56:08 +00:00
if user is None:
return shoot(404, "No such user")
2019-11-11 08:56:08 +00:00
return JSONResponse(user.json())