2020-03-14 00:57:29 +00:00
|
|
|
from royalnet.utils import *
|
|
|
|
from royalnet.backpack.tables import *
|
|
|
|
from royalnet.constellation.api import *
|
|
|
|
from ..tables import DndCharacter
|
|
|
|
|
|
|
|
|
2020-06-22 17:44:58 +00:00
|
|
|
class ApiDndCharacterStar(ApiStar):
|
|
|
|
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-22 17:44:58 +00:00
|
|
|
async def get(self, data: ApiData) -> dict:
|
|
|
|
"""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"]
|
|
|
|
|
|
|
|
character = await asyncify(
|
|
|
|
data.session
|
|
|
|
.query(DndCharacterT)
|
|
|
|
.filter_by(character_id=character_id)
|
|
|
|
.one_or_none
|
|
|
|
)
|
|
|
|
|
|
|
|
if character is None:
|
|
|
|
raise NotFoundError(f"No character with id '{character_id}' found")
|
|
|
|
|
|
|
|
return character.json()
|