Browse Source

collection api revised

CJYen 3 years ago
parent
commit
2b4a810590
1 changed files with 7 additions and 20 deletions
  1. 7 20
      main.py

+ 7 - 20
main.py

@@ -170,34 +170,21 @@ def message(event):
 # nft collection api
 @app.get("/collection/{userid}")
 def collection(userid):
+    # 連到ownership表單去找,並回傳json
     # db connect
     db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
-    table3 = db['nftdrops']
-    table2 = db['nft']
-    nftdrops = {}
+    table1 = db['ownership']
     nft = {}
-    nfts_all = {}
     i = 0
-    j = 0
-    if not table3.find_one(userid=userid) and not table2.find_one(userid=userid):
+    if not table1.find_one(userid=userid):
         db.close()
         return "error: user don't have any nft"
-
     else:
-        results1 = table3.find(userid=userid)
-        for item in results1:
-            nft_id = item['nftid']
-            nftdrops[i] = table2.find_one(id=nft_id)
+        results = db.query("SELECT nftid, amount FROM arkcard.ownership WHERE userid IN (SELECT userid FROM arkcard.ownership WHERE userid = '"+userid+"');")
+        for item in results:
+            nft[i] = item
             i += 1
-
-        results2 = table2.find(userid=userid)
-        for item in results2:
-            nft[j] = item
-            j += 1
-
-        nfts_all[0] = nftdrops
-        nfts_all[1] = nft
-        return nfts_all
+        return nft
         db.close()