|
@@ -18,28 +18,11 @@ from app import crud, models, schemas
|
|
|
from typing import Callable, List
|
|
|
from uuid import uuid4
|
|
|
from sqlalchemy.orm import Session
|
|
|
+from datetime import datetime
|
|
|
|
|
|
|
|
|
-class ContextIncludedRoute(APIRoute):
|
|
|
- def get_route_handler(self) -> Callable:
|
|
|
- original_route_handler = super().get_route_handler()
|
|
|
|
|
|
- async def custom_route_handler(request: Request
|
|
|
- ,db: Session = Depends(deps.get_db)) -> Response:
|
|
|
- request_id = str(uuid4())
|
|
|
- response: Response = await original_route_handler(request)
|
|
|
-
|
|
|
- if await request.body():
|
|
|
- print(await request.body())
|
|
|
- print(request.url)
|
|
|
- print(request.headers)
|
|
|
-
|
|
|
- response.headers["Request-ID"] = request_id
|
|
|
- return response
|
|
|
-
|
|
|
- return custom_route_handler
|
|
|
-
|
|
|
-router = APIRouter(route_class=ContextIncludedRoute)
|
|
|
+router = APIRouter()
|
|
|
|
|
|
|
|
|
# callback event
|
|
@@ -265,6 +248,7 @@ async def send(userModel: line.TransactionNft):
|
|
|
table = db['users']
|
|
|
table2 = db['nft']
|
|
|
table3 = db['nftdrops']
|
|
|
+ transaction_table = db['transaction']
|
|
|
|
|
|
# input and find userid
|
|
|
nftid = userModel.nftid
|
|
@@ -286,9 +270,10 @@ async def send(userModel: line.TransactionNft):
|
|
|
# push訊息
|
|
|
result3 = table2.find_one(id=nftid)
|
|
|
title = result3['title']
|
|
|
+ pre_own = result3['userid']
|
|
|
message = "您的NFT : " + title + ", 已劃轉成功!"
|
|
|
push_text(userid, message)
|
|
|
-
|
|
|
+ transaction_table.insert({'tfrom':pre_own,'to':userid,'nft':nftid,'transaction_at':datetime.now()})
|
|
|
db.close()
|
|
|
elif table2.find_one(id=nftid):
|
|
|
result3 = table2.find_one(id=nftid)
|
|
@@ -299,6 +284,7 @@ async def send(userModel: line.TransactionNft):
|
|
|
|
|
|
# push訊息
|
|
|
try:
|
|
|
+ transaction_table.insert({'tfrom':pre_own,'to':userid,'nft':nftid,'transaction_at':datetime.now()})
|
|
|
title = result3['title']
|
|
|
fr = "您的NFT : " + title + ", 已發送成功!"
|
|
|
to = "您的NFT : "+title+", 已收到!"
|
|
@@ -411,3 +397,28 @@ async def nftdrops(userModel: line.NftDrops):
|
|
|
message = "您已登記過活動了!"
|
|
|
push_text(userid, message)
|
|
|
return "已有資料"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+@router.get("/transactions/{userid}")
|
|
|
+def transactions(userid,skip: int = 0, limit: int = 100):
|
|
|
+ # db connect
|
|
|
+ db = dataset.connect(
|
|
|
+ 'mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4'
|
|
|
+ )
|
|
|
+
|
|
|
+ sql = 'SELECT * FROM transaction ' \
|
|
|
+ 'WHERE tfrom="'+userid+'" limit '+str(skip)+', '+str(limit)
|
|
|
+ result = db.query(sql)
|
|
|
+ rows = {}
|
|
|
+ i = 0
|
|
|
+ for row in result:
|
|
|
+ rows[i] = row
|
|
|
+ i += 1
|
|
|
+ db.close()
|
|
|
+
|
|
|
+ return rows
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|