Add paid column and handle it in the app

This commit is contained in:
2026-06-15 19:02:52 -04:00
parent 08f92c068e
commit 3defdc3aab

13
app.py
View File

@@ -33,6 +33,7 @@ def initialize_database():
user_id INTEGER NOT NULL, user_id INTEGER NOT NULL,
entrytype TEXT NOT NULL CHECK(entrytype IN ('in', 'out')), entrytype TEXT NOT NULL CHECK(entrytype IN ('in', 'out')),
ts TEXT NOT NULL, ts TEXT NOT NULL,
paid BOOLEAN NOT NULL DEFAULT FALSE,
FOREIGN KEY(user_id) REFERENCES users(id) FOREIGN KEY(user_id) REFERENCES users(id)
) )
""") """)
@@ -64,9 +65,9 @@ def create_entry(user_id, entry_type, client_timestamp=None):
else: else:
timestamp = utc_now() timestamp = utc_now()
cursor.execute(""" cursor.execute("""
INSERT INTO entries (user_id, entrytype, ts) INSERT INTO entries (user_id, entrytype, ts, paid)
VALUES (?, ?, ?) VALUES (?, ?, ?, ?)
""", (user_id, entry_type, timestamp.isoformat())) """, (user_id, entry_type, timestamp.isoformat(), False))
conn.commit() conn.commit()
conn.close() conn.close()
@@ -202,7 +203,7 @@ def api_get_users():
def api_get_entries(): def api_get_entries():
conn = get_db_connection() conn = get_db_connection()
entries = conn.execute(""" entries = conn.execute("""
SELECT id, user_id, entrytype, ts SELECT id, user_id, entrytype, ts, paid
FROM entries FROM entries
ORDER BY ts DESC ORDER BY ts DESC
""").fetchall() """).fetchall()
@@ -215,6 +216,7 @@ def api_create_entry():
user_id = data.get("user_id") user_id = data.get("user_id")
entry_type = data.get("entrytype") entry_type = data.get("entrytype")
client_timestamp = data.get("timestamp") client_timestamp = data.get("timestamp")
paid = data.get("paid", False)
if entry_type not in ("in", "out"): if entry_type not in ("in", "out"):
return jsonify({ return jsonify({
"error": "Invalid entrytype" "error": "Invalid entrytype"
@@ -222,7 +224,8 @@ def api_create_entry():
create_entry( create_entry(
user_id, user_id,
entry_type, entry_type,
client_timestamp client_timestamp,
paid
) )
return jsonify({ return jsonify({
"status": "success" "status": "success"