From dbf867fb7a02c0f408fb770b18cffc429cfbee1d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 29 Apr 2020 18:49:37 +0200 Subject: [PATCH] Add timestamp column to fiorygi transactions --- royalpack/stars/api_fiorygi_get.py | 5 ++++- royalpack/tables/fiorygitransactions.py | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/royalpack/stars/api_fiorygi_get.py b/royalpack/stars/api_fiorygi_get.py index 60da931b..64cf1ad7 100644 --- a/royalpack/stars/api_fiorygi_get.py +++ b/royalpack/stars/api_fiorygi_get.py @@ -29,5 +29,8 @@ class ApiFiorygiGetStar(ApiStar): 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)) + "transactions": list(map(lambda t: {"id": t.id, + "change": t.change, + "reason": t.reason, + "timestamp": t.timestamp.isoformat()}, transactions)) } diff --git a/royalpack/tables/fiorygitransactions.py b/royalpack/tables/fiorygitransactions.py index 47c0cb94..42366729 100644 --- a/royalpack/tables/fiorygitransactions.py +++ b/royalpack/tables/fiorygitransactions.py @@ -1,11 +1,11 @@ from typing import * +import datetime from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declared_attr from .fiorygi import Fiorygi -from royalnet.utils import asyncify if TYPE_CHECKING: from royalnet.commands import CommandData @@ -38,6 +38,10 @@ class FiorygiTransaction: def reason(self): return Column(String, nullable=False, default="") + @declared_attr + def timestamp(self): + return Column(DateTime) + def __repr__(self): 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)( user_id=user.uid, change=qty, - reason=reason + reason=reason, + timestamp=datetime.datetime.now() ) data.session.add(transaction)