1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00
royalnet/royalpack/stars/api_user_get_ryg.py

39 lines
1.3 KiB
Python
Raw Normal View History

2020-06-19 15:39:46 +00:00
import royalnet.constellation.api as rca
import royalnet.utils as ru
import royalnet.backpack.tables as rbt
class ApiUserGetRygStar(rca.ApiStar):
summary = "Ottieni le informazioni su un utente della Royal Games."
description = ""
methods = ["GET"]
path = "/api/user/get/ryg/v1"
requires_auth = False
parameters = {"id": "L'id dell'utente di cui vuoi vedere le informazioni."}
tags = ["user"]
async def api(self, data: rca.ApiData) -> dict:
user_id_str = data["id"]
try:
user_id = int(user_id_str)
except (ValueError, TypeError):
raise rca.InvalidParameterError("'id' is not a valid int.")
user: rbt.User = await ru.asyncify(data.session.query(self.alchemy.get(rbt.User)).get, user_id)
if user is None:
raise rca.NotFoundError("No such user.")
result = {
**user.json(),
2020-06-19 16:16:50 +00:00
"bio": user.bio.json() if user.bio is not None else None,
2020-06-19 15:39:46 +00:00
"fiorygi": user.fiorygi.fiorygi if user.fiorygi is not None else None,
"steam": [steam.json() for steam in user.steam],
"leagueoflegends": [leagueoflegends.json() for leagueoflegends in user.leagueoflegends],
"trivia": user.trivia_score.json() if user.trivia_score is not None else None
}
return result