1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add fiorygi get star

This commit is contained in:
Steffo 2020-03-18 17:35:08 +01:00
parent b3699f02f4
commit 50e188df3b
3 changed files with 40 additions and 1 deletions

View file

@ -8,6 +8,7 @@ from .api_discord_play import ApiDiscordPlayStar
from .api_wiki_edit import ApiWikiEditStar
from .api_wiki_get import ApiWikiGetStar
from .api_wiki_list import ApiWikiListStar
from .api_fiorygi_get import ApiFiorygiGetStar
# Enter the PageStars of your Pack here!
available_page_stars = [
@ -20,6 +21,7 @@ available_page_stars = [
ApiWikiEditStar,
ApiWikiGetStar,
ApiWikiListStar,
ApiFiorygiGetStar,
]
# Don't change this, it should automatically generate __all__

View file

@ -0,0 +1,33 @@
from typing import *
from royalnet.utils import *
from royalnet.backpack.tables import *
from royalnet.constellation.api import *
from ..utils import find_user_api
from ..tables import Fiorygi, FiorygiTransaction
class ApiFiorygiGetStar(ApiStar):
path = "/api/user/fiorygi/get/v1"
summary = "Get the fiorygi of a Royalnet user."
parameters = {
"id": "The user to get the fiorygi of."
}
tags = ["user"]
async def api(self, data: ApiData) -> JSON:
user: User = await find_user_api(data["id"], self.alchemy, data.session)
if user.fiorygi is None:
return {
"fiorygi": 0,
"transactions": [],
"warning": "No associated fiorygi table"
}
fiorygi: Fiorygi = user.fiorygi
transactions: JSON = sorted(fiorygi.transactions, key=lambda t: -t.id)
return {
"fiorygi": fiorygi.fiorygi,
"transactions": list(map(lambda t: {"id": t.id, "change": t.change, "reason": t.reason}, transactions))
}

View file

@ -19,9 +19,13 @@ class FiorygiTransaction:
return Column(Integer, ForeignKey("fiorygi.user_id"), nullable=False)
@declared_attr
def user(self):
def wallet(self):
return relationship("Fiorygi", backref=backref("transactions"))
@property
def user(self):
return self.wallet.user
@declared_attr
def reason(self):
return Column(String, nullable=False, default="")