|
@@ -13,10 +13,11 @@ import qrcode
|
|
|
# from PIL import Image
|
|
|
# import base64, io
|
|
|
from random import randrange
|
|
|
-import models
|
|
|
+from app.api.api_v1.endpoints import models
|
|
|
import datetime as dt
|
|
|
+from fastapi import APIRouter
|
|
|
|
|
|
-app = fastapi.FastAPI()
|
|
|
+router = APIRouter()
|
|
|
|
|
|
|
|
|
# bot config
|
|
@@ -24,7 +25,7 @@ line_bot_api = LineBotApi("SJT7VPT4RMQFLcS27jQBy3FcC24gtDrkcwJWZ5Xzqesr5T78LOKud
|
|
|
handler = WebhookHandler("411ae3ef7e766739ed2c2c27b249d010")
|
|
|
|
|
|
# callback event
|
|
|
-@app.post("/callback")
|
|
|
+@router.post("/callback")
|
|
|
async def callback(request: fastapi.Request):
|
|
|
signature = request.headers['X-Line-Signature']
|
|
|
body = await request.body()
|
|
@@ -160,7 +161,7 @@ def message(event):
|
|
|
template=button_template_message))
|
|
|
|
|
|
# nft collection api
|
|
|
-@app.get("/collection/{userid}")
|
|
|
+@router.get("/collection/{userid}")
|
|
|
def collection(userid):
|
|
|
# 連到ownership表單去找,並回傳json
|
|
|
# db connect
|
|
@@ -180,7 +181,7 @@ def collection(userid):
|
|
|
return nft
|
|
|
|
|
|
# receive handler
|
|
|
-@app.get("/receive/{userid}")
|
|
|
+@router.get("/receive/{userid}")
|
|
|
def receive(userid):
|
|
|
# 確定要傳送的對象,到user去找到它
|
|
|
# db connect
|
|
@@ -196,7 +197,7 @@ def receive(userid):
|
|
|
return {"userid": result['userid'], "address": result['address']}
|
|
|
|
|
|
# send handler
|
|
|
-@app.post("/send")
|
|
|
+@router.post("/send")
|
|
|
async def receive(userModel : models.TransactionNft):
|
|
|
# 從網頁上選定好商品,在選定好數量後輸入收方地址;將把該商品轉到收方,並存下交易記錄
|
|
|
# 從ownership找到該userid的擁有人,再把擁有人userid改為收方,並在trans留下記錄
|
|
@@ -270,7 +271,7 @@ async def receive(userModel : models.TransactionNft):
|
|
|
return {"messge: NFT 夠"}
|
|
|
|
|
|
# shop handler
|
|
|
-@app.get("/shop")
|
|
|
+@router.get("/shop")
|
|
|
def shop():
|
|
|
# 為了顯示正確的nft網頁和數量,直接顯示nft表出來
|
|
|
# db connect
|
|
@@ -284,7 +285,7 @@ def shop():
|
|
|
return nfts
|
|
|
db.close()
|
|
|
|
|
|
-@app.post("/buy")
|
|
|
+@router.post("/buy")
|
|
|
async def buy(userModel : models.BuyNft):
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
@@ -333,7 +334,7 @@ async def buy(userModel : models.BuyNft):
|
|
|
db.close()
|
|
|
return "您已購買成功!"
|
|
|
|
|
|
-@app.post("/event")
|
|
|
+@router.post("/event")
|
|
|
async def nftdrops(userModel : models.NftDrops):
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
@@ -360,7 +361,7 @@ async def nftdrops(userModel : models.NftDrops):
|
|
|
db.close()
|
|
|
return "該資料已存在"
|
|
|
|
|
|
-@app.post("/eventPeriod")
|
|
|
+@router.post("/eventPeriod")
|
|
|
def eventPeriod():
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|