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

40 lines
1.2 KiB
Python
Raw Normal View History

2020-03-18 16:35:08 +00:00
from typing import *
2020-06-26 14:13:11 +00:00
import royalnet.utils as ru
import royalnet.backpack.tables as rbt
import royalnet.constellation.api as rca
2020-06-22 17:27:11 +00:00
from ..tables import Fiorygi
2020-03-18 16:35:08 +00:00
2020-06-26 14:13:11 +00:00
class ApiFiorygiStar(rca.ApiStar):
2020-06-22 17:27:11 +00:00
path = "/api/fiorygi/v2"
2020-03-18 16:35:08 +00:00
parameters = {
2020-06-22 17:27:11 +00:00
"get": {
"uid": "The user to get the fiorygi of."
}
2020-03-18 16:35:08 +00:00
}
2020-06-22 17:27:11 +00:00
tags = ["fiorygi"]
2020-03-18 16:35:08 +00:00
2020-06-26 14:13:11 +00:00
@rca.magic
async def get(self, data: rca.ApiData) -> ru.JSON:
2020-06-22 17:27:11 +00:00
"""Get fiorygi information about a specific user."""
2020-06-26 14:13:11 +00:00
user = await rbt.User.find(self.alchemy, data.session, data.int("uid"))
2020-03-18 16:35:08 +00:00
if user.fiorygi is None:
return {
"fiorygi": 0,
"transactions": [],
"warning": "No associated fiorygi table"
}
fiorygi: Fiorygi = user.fiorygi
2020-06-26 14:13:11 +00:00
transactions: ru.JSON = sorted(fiorygi.transactions, key=lambda t: -t.id)
2020-03-18 16:35:08 +00:00
return {
"fiorygi": fiorygi.fiorygi,
2020-05-02 23:53:15 +00:00
"transactions": list(map(lambda t: {
"id": t.id,
"change": t.change,
"reason": t.reason,
"timestamp": t.timestamp.isoformat() if t.timestamp else None
}, transactions))
2020-03-18 16:35:08 +00:00
}