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:
parent
b3699f02f4
commit
50e188df3b
3 changed files with 40 additions and 1 deletions
|
@ -8,6 +8,7 @@ from .api_discord_play import ApiDiscordPlayStar
|
||||||
from .api_wiki_edit import ApiWikiEditStar
|
from .api_wiki_edit import ApiWikiEditStar
|
||||||
from .api_wiki_get import ApiWikiGetStar
|
from .api_wiki_get import ApiWikiGetStar
|
||||||
from .api_wiki_list import ApiWikiListStar
|
from .api_wiki_list import ApiWikiListStar
|
||||||
|
from .api_fiorygi_get import ApiFiorygiGetStar
|
||||||
|
|
||||||
# Enter the PageStars of your Pack here!
|
# Enter the PageStars of your Pack here!
|
||||||
available_page_stars = [
|
available_page_stars = [
|
||||||
|
@ -20,6 +21,7 @@ available_page_stars = [
|
||||||
ApiWikiEditStar,
|
ApiWikiEditStar,
|
||||||
ApiWikiGetStar,
|
ApiWikiGetStar,
|
||||||
ApiWikiListStar,
|
ApiWikiListStar,
|
||||||
|
ApiFiorygiGetStar,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Don't change this, it should automatically generate __all__
|
# Don't change this, it should automatically generate __all__
|
||||||
|
|
33
royalpack/stars/api_fiorygi_get.py
Normal file
33
royalpack/stars/api_fiorygi_get.py
Normal 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))
|
||||||
|
}
|
|
@ -19,9 +19,13 @@ class FiorygiTransaction:
|
||||||
return Column(Integer, ForeignKey("fiorygi.user_id"), nullable=False)
|
return Column(Integer, ForeignKey("fiorygi.user_id"), nullable=False)
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def user(self):
|
def wallet(self):
|
||||||
return relationship("Fiorygi", backref=backref("transactions"))
|
return relationship("Fiorygi", backref=backref("transactions"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user(self):
|
||||||
|
return self.wallet.user
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def reason(self):
|
def reason(self):
|
||||||
return Column(String, nullable=False, default="")
|
return Column(String, nullable=False, default="")
|
||||||
|
|
Loading…
Reference in a new issue