api repariert
This commit is contained in:
parent
c19fa0a2de
commit
85fc8b461d
2 changed files with 10 additions and 7 deletions
|
@ -5,7 +5,7 @@ from flask_session import Session
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
from .db import get_db
|
from .db import get_db
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
finished = None
|
||||||
|
|
||||||
#flask_config
|
#flask_config
|
||||||
DATABASE = './Website/mate.db'
|
DATABASE = './Website/mate.db'
|
||||||
|
@ -134,7 +134,7 @@ def create_app(test_config=None):
|
||||||
</script>
|
</script>
|
||||||
<title>{escape(user[1])}</title>
|
<title>{escape(user[1])}</title>
|
||||||
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
||||||
<p> {escape(user[1])} : {user[2]}€ <p>
|
<p> {escape(user[1])} : {escape(user[2])}€ <p>
|
||||||
<form action="/addtag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Add Tag</button></form>
|
<form action="/addtag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Add Tag</button></form>
|
||||||
<form action="/removetag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove Tag</button></form>
|
<form action="/removetag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove Tag</button></form>
|
||||||
</p><form action="/change" method="post"><input name="id" type="hidden" value="{user[0]}"> <input name="change" type="number" step="0.1" placeholder="change balance"></form>
|
</p><form action="/change" method="post"><input name="id" type="hidden" value="{user[0]}"> <input name="change" type="number" step="0.1" placeholder="change balance"></form>
|
||||||
|
@ -206,6 +206,7 @@ def create_app(test_config=None):
|
||||||
try:
|
try:
|
||||||
user_id = request.form["id"]
|
user_id = request.form["id"]
|
||||||
change = float(request.form["change"])
|
change = float(request.form["change"])
|
||||||
|
print(change)
|
||||||
except:
|
except:
|
||||||
return render_template("error.html", error_code="095")
|
return render_template("error.html", error_code="095")
|
||||||
c.execute(f"SELECT * FROM users WHERE id=?", [user_id])
|
c.execute(f"SELECT * FROM users WHERE id=?", [user_id])
|
||||||
|
@ -345,7 +346,7 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
state = queue_item[1]
|
state = queue_item[1]
|
||||||
c.execute(f"SELECT * FROM users WHERE id=?", [user])
|
c.execute(f"SELECT * FROM users WHERE id=?", [user])
|
||||||
user = c.fetchall()
|
user = c.fetchone()
|
||||||
user_id = user[0]
|
user_id = user[0]
|
||||||
username = user[1]
|
username = user[1]
|
||||||
if state == "add":
|
if state == "add":
|
||||||
|
@ -355,17 +356,19 @@ def create_app(test_config=None):
|
||||||
finished = queue_item
|
finished = queue_item
|
||||||
return make_response(json.dumps({"mode":"error","error":"170"}))
|
return make_response(json.dumps({"mode":"error","error":"170"}))
|
||||||
else:
|
else:
|
||||||
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, ?)", [user])
|
c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, ?)", [user_id])
|
||||||
db.commit()
|
db.commit()
|
||||||
|
message = f"Added {tag_id} to {username}"
|
||||||
log(type="addtag", userid=user_id ,after=tag_id)
|
log(type="addtag", userid=user_id ,after=tag_id)
|
||||||
finished = queue_item
|
finished = queue_item
|
||||||
return make_response(json.dumps({"mode":"message","username":"{}".format(username),"message":"A tag was added"}))
|
return make_response(json.dumps({"mode":"message","username":"{}".format(username),"message":"A tag was added"}))
|
||||||
elif state == "remove":
|
elif state == "remove":
|
||||||
c.execute(f"SELECT * FROM tags WHERE (tagid = {tag_id} AND userid = ?)", [user])
|
c.execute(f"SELECT * FROM tags WHERE (tagid = {tag_id} AND userid = ?)", [user_id])
|
||||||
tags = c.fetchall()
|
tags = c.fetchall()
|
||||||
if tags != []:
|
if tags != []:
|
||||||
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = ?)", [user])
|
c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = ?)", [user_id])
|
||||||
db.commit()
|
db.commit()
|
||||||
|
message = f"Removed {tag_id} from {username}"
|
||||||
log(type="removetag", userid=user_id, before=tag_id)
|
log(type="removetag", userid=user_id, before=tag_id)
|
||||||
finished = queue_item
|
finished = queue_item
|
||||||
return make_response(json.dumps({"mode":"message","username":"{}".format(username),"message":"A tag was removed"}))
|
return make_response(json.dumps({"mode":"message","username":"{}".format(username),"message":"A tag was removed"}))
|
||||||
|
|
|
@ -6,7 +6,7 @@ CREATE TABLE IF NOT EXISTS "users" (
|
||||||
PRIMARY KEY("id")
|
PRIMARY KEY("id")
|
||||||
);
|
);
|
||||||
CREATE TABLE IF NOT EXISTS "tags" (
|
CREATE TABLE IF NOT EXISTS "tags" (
|
||||||
"tagid" INTEGER NOT NULL,
|
"tagid" INEGER NOT NULL,
|
||||||
"userid" INTEGER,
|
"userid" INTEGER,
|
||||||
FOREIGN KEY("userid") REFERENCES "users"("id"),
|
FOREIGN KEY("userid") REFERENCES "users"("id"),
|
||||||
PRIMARY KEY("tagid")
|
PRIMARY KEY("tagid")
|
||||||
|
|
Loading…
Reference in a new issue