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

35 lines
894 B
Python
Raw Permalink Normal View History

2020-06-26 14:17:07 +00:00
import royalnet.utils as ru
import royalnet.constellation.api as rca
2020-03-14 00:57:29 +00:00
from ..tables import DndCharacter
2020-06-26 14:17:07 +00:00
class ApiDndCharacterStar(rca.ApiStar):
2020-06-22 17:44:58 +00:00
path = "/api/dnd/character/v2"
2020-03-14 00:57:29 +00:00
parameters = {
2020-06-22 17:44:58 +00:00
"get": {
"character_id": "The id of the character to get."
}
2020-03-14 00:57:29 +00:00
}
tags = ["dnd"]
2020-06-26 14:17:07 +00:00
@rca.magic
async def get(self, data: rca.ApiData) -> dict:
2020-06-22 17:44:58 +00:00
"""Get the character sheet of a specific D&D Character."""
2020-03-14 00:57:29 +00:00
DndCharacterT = self.alchemy.get(DndCharacter)
character_id = data["character_id"]
2020-06-26 14:17:07 +00:00
character = await ru.asyncify(
2020-03-14 00:57:29 +00:00
data.session
.query(DndCharacterT)
.filter_by(character_id=character_id)
.one_or_none
)
if character is None:
2020-06-26 14:17:07 +00:00
raise rca.NotFoundError(f"No character with id '{character_id}' found")
2020-03-14 00:57:29 +00:00
return character.json()