Version 9b #1
|
|
@ -198,8 +198,8 @@ def update_profile(pid: str, p: ProfileUpdate, session=Depends(require_auth)):
|
||||||
def delete_profile(pid: str, session=Depends(require_auth)):
|
def delete_profile(pid: str, session=Depends(require_auth)):
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
cur.execute("SELECT COUNT(*) FROM profiles")
|
cur.execute("SELECT COUNT(*) as count FROM profiles")
|
||||||
count = cur.fetchone()[0]
|
count = cur.fetchone()['count']
|
||||||
if count <= 1: raise HTTPException(400, "Letztes Profil kann nicht gelöscht werden")
|
if count <= 1: raise HTTPException(400, "Letztes Profil kann nicht gelöscht werden")
|
||||||
for table in ['weight_log','circumference_log','caliper_log','nutrition_log','activity_log','ai_insights']:
|
for table in ['weight_log','circumference_log','caliper_log','nutrition_log','activity_log','ai_insights']:
|
||||||
cur.execute(f"DELETE FROM {table} WHERE profile_id=%s", (pid,))
|
cur.execute(f"DELETE FROM {table} WHERE profile_id=%s", (pid,))
|
||||||
|
|
@ -623,16 +623,16 @@ def get_stats(x_profile_id: Optional[str]=Header(default=None), session: dict=De
|
||||||
pid = get_pid(x_profile_id)
|
pid = get_pid(x_profile_id)
|
||||||
with get_db() as conn:
|
with get_db() as conn:
|
||||||
cur = get_cursor(conn)
|
cur = get_cursor(conn)
|
||||||
cur.execute("SELECT COUNT(*) FROM weight_log WHERE profile_id=%s",(pid,))
|
cur.execute("SELECT COUNT(*) as count FROM weight_log WHERE profile_id=%s",(pid,))
|
||||||
weight_count = cur.fetchone()[0]
|
weight_count = cur.fetchone()['count']
|
||||||
cur.execute("SELECT COUNT(*) FROM circumference_log WHERE profile_id=%s",(pid,))
|
cur.execute("SELECT COUNT(*) as count FROM circumference_log WHERE profile_id=%s",(pid,))
|
||||||
circ_count = cur.fetchone()[0]
|
circ_count = cur.fetchone()['count']
|
||||||
cur.execute("SELECT COUNT(*) FROM caliper_log WHERE profile_id=%s",(pid,))
|
cur.execute("SELECT COUNT(*) as count FROM caliper_log WHERE profile_id=%s",(pid,))
|
||||||
caliper_count = cur.fetchone()[0]
|
caliper_count = cur.fetchone()['count']
|
||||||
cur.execute("SELECT COUNT(*) FROM nutrition_log WHERE profile_id=%s",(pid,))
|
cur.execute("SELECT COUNT(*) as count FROM nutrition_log WHERE profile_id=%s",(pid,))
|
||||||
nutrition_count = cur.fetchone()[0]
|
nutrition_count = cur.fetchone()['count']
|
||||||
cur.execute("SELECT COUNT(*) FROM activity_log WHERE profile_id=%s",(pid,))
|
cur.execute("SELECT COUNT(*) as count FROM activity_log WHERE profile_id=%s",(pid,))
|
||||||
activity_count = cur.fetchone()[0]
|
activity_count = cur.fetchone()['count']
|
||||||
return {
|
return {
|
||||||
"weight_count": weight_count,
|
"weight_count": weight_count,
|
||||||
"circ_count": circ_count,
|
"circ_count": circ_count,
|
||||||
|
|
@ -1204,10 +1204,10 @@ def admin_list_profiles(session: dict=Depends(require_admin)):
|
||||||
|
|
||||||
for p in profs:
|
for p in profs:
|
||||||
pid = p['id']
|
pid = p['id']
|
||||||
cur.execute("SELECT COUNT(*) FROM weight_log WHERE profile_id=%s", (pid,))
|
cur.execute("SELECT COUNT(*) as count FROM weight_log WHERE profile_id=%s", (pid,))
|
||||||
p['weight_count'] = cur.fetchone()[0]
|
p['weight_count'] = cur.fetchone()['count']
|
||||||
cur.execute("SELECT COUNT(*) FROM ai_insights WHERE profile_id=%s", (pid,))
|
cur.execute("SELECT COUNT(*) as count FROM ai_insights WHERE profile_id=%s", (pid,))
|
||||||
p['ai_insights_count'] = cur.fetchone()[0]
|
p['ai_insights_count'] = cur.fetchone()['count']
|
||||||
|
|
||||||
today = datetime.now().date().isoformat()
|
today = datetime.now().date().isoformat()
|
||||||
cur.execute("SELECT call_count FROM ai_usage WHERE profile_id=%s AND date=%s", (pid, today))
|
cur.execute("SELECT call_count FROM ai_usage WHERE profile_id=%s AND date=%s", (pid, today))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user