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

Add timestamp column to fiorygi transactions

This commit is contained in:
Steffo 2020-04-29 18:49:37 +02:00
parent eace2231c4
commit dbf867fb7a
2 changed files with 11 additions and 3 deletions

View file

@ -29,5 +29,8 @@ class ApiFiorygiGetStar(ApiStar):
transactions: JSON = sorted(fiorygi.transactions, key=lambda t: -t.id) transactions: JSON = sorted(fiorygi.transactions, key=lambda t: -t.id)
return { return {
"fiorygi": fiorygi.fiorygi, "fiorygi": fiorygi.fiorygi,
"transactions": list(map(lambda t: {"id": t.id, "change": t.change, "reason": t.reason}, transactions)) "transactions": list(map(lambda t: {"id": t.id,
"change": t.change,
"reason": t.reason,
"timestamp": t.timestamp.isoformat()}, transactions))
} }

View file

@ -1,11 +1,11 @@
from typing import * from typing import *
import datetime
from sqlalchemy import * from sqlalchemy import *
from sqlalchemy.orm import * from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
from .fiorygi import Fiorygi from .fiorygi import Fiorygi
from royalnet.utils import asyncify
if TYPE_CHECKING: if TYPE_CHECKING:
from royalnet.commands import CommandData from royalnet.commands import CommandData
@ -38,6 +38,10 @@ class FiorygiTransaction:
def reason(self): def reason(self):
return Column(String, nullable=False, default="") return Column(String, nullable=False, default="")
@declared_attr
def timestamp(self):
return Column(DateTime)
def __repr__(self): def __repr__(self):
return f"<{self.__class__.__name__}: {self.change:+} to {self.user.username} for {self.reason}>" return f"<{self.__class__.__name__}: {self.change:+} to {self.user.username} for {self.reason}>"
@ -53,7 +57,8 @@ class FiorygiTransaction:
transaction = data._interface.alchemy.get(FiorygiTransaction)( transaction = data._interface.alchemy.get(FiorygiTransaction)(
user_id=user.uid, user_id=user.uid,
change=qty, change=qty,
reason=reason reason=reason,
timestamp=datetime.datetime.now()
) )
data.session.add(transaction) data.session.add(transaction)