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 .db import get_db
|
||||
from datetime import datetime
|
||||
|
||||
finished = None
|
||||
|
||||
#flask_config
|
||||
DATABASE = './Website/mate.db'
|
||||
|
@ -134,7 +134,7 @@ def create_app(test_config=None):
|
|||
</script>
|
||||
<title>{escape(user[1])}</title>
|
||||
<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="/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>
|
||||
|
@ -206,6 +206,7 @@ def create_app(test_config=None):
|
|||
try:
|
||||
user_id = request.form["id"]
|
||||
change = float(request.form["change"])
|
||||
print(change)
|
||||
except:
|
||||
return render_template("error.html", error_code="095")
|
||||
c.execute(f"SELECT * FROM users WHERE id=?", [user_id])
|
||||
|
@ -345,7 +346,7 @@ def create_app(test_config=None):
|
|||
|
||||
state = queue_item[1]
|
||||
c.execute(f"SELECT * FROM users WHERE id=?", [user])
|
||||
user = c.fetchall()
|
||||
user = c.fetchone()
|
||||
user_id = user[0]
|
||||
username = user[1]
|
||||
if state == "add":
|
||||
|
@ -355,17 +356,19 @@ def create_app(test_config=None):
|
|||
finished = queue_item
|
||||
return make_response(json.dumps({"mode":"error","error":"170"}))
|
||||
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()
|
||||
message = f"Added {tag_id} to {username}"
|
||||
log(type="addtag", userid=user_id ,after=tag_id)
|
||||
finished = queue_item
|
||||
return make_response(json.dumps({"mode":"message","username":"{}".format(username),"message":"A tag was added"}))
|
||||
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()
|
||||
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()
|
||||
message = f"Removed {tag_id} from {username}"
|
||||
log(type="removetag", userid=user_id, before=tag_id)
|
||||
finished = queue_item
|
||||
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")
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS "tags" (
|
||||
"tagid" INTEGER NOT NULL,
|
||||
"tagid" INEGER NOT NULL,
|
||||
"userid" INTEGER,
|
||||
FOREIGN KEY("userid") REFERENCES "users"("id"),
|
||||
PRIMARY KEY("tagid")
|
||||
|
|
Loading…
Reference in a new issue