balance get api

This commit is contained in:
bton 2024-02-20 17:33:56 +01:00
parent 55124040ae
commit d55b7c5aea
2 changed files with 35 additions and 22 deletions

View file

@ -249,9 +249,9 @@ def create_app(test_config=None):
socketio.emit("error", "418", to=session[id])
leave_room(session[id])
#api
@app.route("/api/balance", methods=['POST'])
@app.route("/api/balance", methods=['POST', 'GET'])
def api_change():
if request.method == 'POST':
db = get_db()
c = db.cursor()
userid = request.form["id"]
@ -273,6 +273,18 @@ def create_app(test_config=None):
else:
return make_response(json.dumps({"mode":"error","error":"043"}))
elif request.method == 'GET':
db = get_db()
c = db.cursor()
userid = reqest.args.get("id")
c.execute("SELECT * FROM users WHERE id=?", [userid])
user = c.fetchone()
if user != None:
return make_response(json.dumps({"mode":"balance", "username":user[1], "balance":user[2]}))
else:
return make_response(json.dumps({"mode":"error", "error":"043"}))
@app.route("/api/tag_id", methods=['POST'])
def get_id():

View file

@ -29,6 +29,7 @@
<p>
If change = None or NaN the change will be -1
</p>
<p>Get method ?id=user_id</p>
<p>
Response:
{"mode":"error" "error":"{error}"} or