CJYen 3 years ago
parent
commit
c06e8acb53
2 changed files with 9 additions and 2 deletions
  1. 6 2
      main.py
  2. 3 0
      models.py

+ 6 - 2
main.py

@@ -223,12 +223,16 @@ def shop(userid):
         i += 1
     return rows
 
-@app.get("/buy/{userid}/{nftid}")
-async def buy(userid,nftid):
+@app.post("/buy")
+async def buy(userModel : models.BuyNft):
     # db connect
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
     table2 = db['nft']
 
+    # input
+    nftid = userModel.nftid
+    userid = userModel.userid
+
     if not table2.find_one(id=nftid):
         print("error: nft not found")
         return "該NFT商品不存在!如果有疑問,請洽網站的服務信箱!"

+ 3 - 0
models.py

@@ -4,4 +4,7 @@ class TransactionNft(BaseModel):
     nftid: str
     address: str
 
+class BuyNft(BaseModel):
+    nftid: int
+    userid: str