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

22 lines
718 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 *
2020-02-09 18:12:34 +00:00
from royalnet.constellation.api import *
2019-11-11 08:56:08 +00:00
2020-02-09 18:12:34 +00:00
class ApiUserGetStar(ApiStar):
path = "/api/user/get/v1"
2019-11-11 08:56:08 +00:00
2020-02-09 18:12:34 +00:00
async def api(self, data: ApiData) -> dict:
user_id_str = data["id"]
2019-11-11 08:56:08 +00:00
try:
2020-02-09 18:12:34 +00:00
user_id = int(user_id_str)
2019-11-11 08:56:08 +00:00
except (ValueError, TypeError):
2020-02-09 18:12:34 +00:00
raise InvalidParameterError("'id' is not a valid int.")
user: User = await asyncify(data.session.query(self.alchemy.get(User)).get, user_id)
2019-11-11 08:56:08 +00:00
if user is None:
2020-02-09 18:12:34 +00:00
raise NotFoundError("No such user.")
return user.json()