|
@@ -37,40 +37,6 @@ async def callback(request: fastapi.Request):
|
|
handler.handle(body.decode('utf-8'), signature)
|
|
handler.handle(body.decode('utf-8'), signature)
|
|
return 'OK'
|
|
return 'OK'
|
|
|
|
|
|
-# nft collection api
|
|
|
|
-@app.get("/collection/{userid}")
|
|
|
|
-def collection(userid):
|
|
|
|
- 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}")
|
|
|
|
-def receive(userid):
|
|
|
|
- if not table.find_one(userid=userid):
|
|
|
|
- return "ERROR: User Not Found"
|
|
|
|
- else:
|
|
|
|
- result = table.find_one(userid=userid)
|
|
|
|
- return {"userid": result['userid'], "base": result['base'], "useraddress": result['useraddress']}
|
|
|
|
-
|
|
|
|
-# TODO send handler 發送nft
|
|
|
|
-# @app.get("/collection/{userid}/{hash}")
|
|
|
|
-# def blockchain():
|
|
|
|
-
|
|
|
|
-# TODO post blockchain api 上鏈nft
|
|
|
|
-# @app.get("/collection/{userid}/{art}")
|
|
|
|
-# def blockchain():
|
|
|
|
-
|
|
|
|
-# TODO get transaction update 取得交易結果
|
|
|
|
-# @app.get("/collection/{userid}")
|
|
|
|
-# def blockchain():
|
|
|
|
-
|
|
|
|
# follow event
|
|
# follow event
|
|
@handler.add(FollowEvent)
|
|
@handler.add(FollowEvent)
|
|
def handle_follow(event):
|
|
def handle_follow(event):
|
|
@@ -199,6 +165,69 @@ def message(event):
|
|
alt_text="Receive",
|
|
alt_text="Receive",
|
|
template=button_template_message))
|
|
template=button_template_message))
|
|
|
|
|
|
|
|
+# nft collection api
|
|
|
|
+@app.get("/collection/{userid}")
|
|
|
|
+def collection(userid):
|
|
|
|
+ # db connect
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
|
|
+
|
|
|
|
+ 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}")
|
|
|
|
+def receive(userid):
|
|
|
|
+ # db connect
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
|
|
+ table = db['users']
|
|
|
|
+
|
|
|
|
+ table.find_one(userid=userid)
|
|
|
|
+ if not table.find_one(userid=userid):
|
|
|
|
+ return "ERROR: User Not Found"
|
|
|
|
+ else:
|
|
|
|
+ result = table.find_one(userid=userid)
|
|
|
|
+ return {"userid": result['userid'], "base": result['base'], "useraddress": result['useraddress']}
|
|
|
|
+
|
|
|
|
+# send handler
|
|
|
|
+@app.post("/send")
|
|
|
|
+async def receive(userModel : models.TransactionNft):
|
|
|
|
+ # db connect
|
|
|
|
+ db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4')
|
|
|
|
+ table2 = db['nft']
|
|
|
|
+
|
|
|
|
+ # input
|
|
|
|
+ nftid = userModel.nftid
|
|
|
|
+ address = userModel.address
|
|
|
|
+
|
|
|
|
+ if not table2.find_one(id=nftid):
|
|
|
|
+ print("error: nft not found")
|
|
|
|
+ return {'msg': 'nft not found'}
|
|
|
|
+ else:
|
|
|
|
+ statement = 'SELECT userid FROM users WHERE useraddress ="'+address+'"'
|
|
|
|
+ for row in db.query(statement):
|
|
|
|
+ result = row['userid']
|
|
|
|
+
|
|
|
|
+ user_obj = table2.find_one(id=nftid)
|
|
|
|
+ user_obj['userid'] = result
|
|
|
|
+ table2.update(dict(user_obj), ['id'])
|
|
|
|
+ return {'msg': 'OK'}
|
|
|
|
+
|
|
|
|
+ # user_obj = table2.find_one(id=nftid)
|
|
|
|
+ # user_obj['userid'] = address
|
|
|
|
+ # table2.update(dict(user_obj), ['id'])
|
|
|
|
+ # return {'msg': 'OK'}
|
|
|
|
+
|
|
|
|
+ # user_obj = next(iter(db.query(sql)))
|
|
|
|
+ # # user_obj['userid'] = r
|
|
|
|
+ # db['nft'].update(dict(user_obj), ['id'])
|
|
|
|
+ # # return type(r)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8228, reload=True)
|
|
uvicorn.run("main:app", host="0.0.0.0", port=8228, reload=True)
|