1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2025-02-25 06:05:03 +00:00
royalnet/royalpack/stars/api_user_get.py

22 lines
718 B
Python
Raw Normal View History

2019-11-11 09:56:08 +01:00
from starlette.requests import Request
from starlette.responses import *
from royalnet.constellation import *
2019-11-11 09:56:08 +01:00
from royalnet.utils import *
from royalnet.backpack.tables import *
2020-02-09 19:12:34 +01:00
from royalnet.constellation.api import *
2019-11-11 09:56:08 +01:00
2020-02-09 19:12:34 +01:00
class ApiUserGetStar(ApiStar):
path = "/api/user/get/v1"
2019-11-11 09:56:08 +01:00
2020-02-09 19:12:34 +01:00
async def api(self, data: ApiData) -> dict:
user_id_str = data["id"]
2019-11-11 09:56:08 +01:00
try:
2020-02-09 19:12:34 +01:00
user_id = int(user_id_str)
2019-11-11 09:56:08 +01:00
except (ValueError, TypeError):
2020-02-09 19:12:34 +01: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 09:56:08 +01:00
if user is None:
2020-02-09 19:12:34 +01:00
raise NotFoundError("No such user.")
return user.json()