|
@@ -152,16 +152,30 @@ def message(event):
|
|
|
def collection(userid):
|
|
|
# db connect
|
|
|
db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
|
+ table1 = db['users']
|
|
|
+ table2 = db['nft']
|
|
|
|
|
|
- xname = userid
|
|
|
- sql = 'SELECT a.* FROM nft a INNER JOIN (SELECT userid FROM users WHERE userid="'+xname+'") b ON b.userid = a.userid'
|
|
|
- result = db.query(sql)
|
|
|
- rows = {}
|
|
|
- i = 0
|
|
|
- for row in result:
|
|
|
- rows[i] = row
|
|
|
- i += 1
|
|
|
- return rows
|
|
|
+ if table1.find_one(userid=userid) and not table2.find_one(userid=userid):
|
|
|
+ sql = 'SELECT * FROM nft WHERE userid IS NULL LIMIT 5'
|
|
|
+ result = db.query(sql)
|
|
|
+ rows = {}
|
|
|
+ i = 0
|
|
|
+ for row in result:
|
|
|
+ rows[i] = row
|
|
|
+ i += 1
|
|
|
+ return rows
|
|
|
+ elif not table2.find_one(userid=userid):
|
|
|
+ return "Error: User not found."
|
|
|
+ else:
|
|
|
+ xname = userid
|
|
|
+ sql = 'SELECT a.* FROM nft a INNER JOIN (SELECT userid FROM users WHERE userid="' + xname + '") b ON b.userid = a.userid'
|
|
|
+ result = db.query(sql)
|
|
|
+ rows = {}
|
|
|
+ i = 0
|
|
|
+ for row in result:
|
|
|
+ rows[i] = row
|
|
|
+ i += 1
|
|
|
+ return rows
|
|
|
|
|
|
# receive handler
|
|
|
@app.get("/receive/{userid}")
|