diff --git a/app.py b/app.py index 12560ec..e6b1f43 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import hashlib from flask import Flask, render_template, redirect, url_for, request from flask_login import login_required, LoginManager, login_user, logout_user, current_user +from models.Habit import Habit from models.User import User from utils import anonymous_required @@ -129,4 +130,4 @@ def logout(): # Run the application if __name__ == '__main__': - app.run(port=5000, debug=True) + app.run(port=5000, debug=True) \ No newline at end of file diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index 99e6c73..28bb449 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -41,6 +41,17 @@ def get_user_by_email(email: str): return user +def delete_user(id: int): + query = f"DELETE FROM habits WHERE user_id = {id};" + query2 = f"DELETE FROM users WHERE id = {id};" + conn = con3() + cursor = conn.cursor() + cursor.execute(query) + cursor.execute(query2) + conn.commit() + conn.close() + + def create_habit(name: str, user_id: int, times: int, unit: int, slot: int, note: str | None=None): now = datetime.now().isoformat() query = (f"INSERT INTO habits (user_id, name, note, times, unit, list_index, created_at, updated_at) VALUES ('{user_id}', " @@ -58,9 +69,9 @@ def get_habit(id: int): conn = con3() cursor = conn.cursor() cursor.execute(query) - habits = cursor.fetchone() + habit = cursor.fetchone() conn.close() - return habits + return habit def get_habits(user_id: int): @@ -68,6 +79,15 @@ def get_habits(user_id: int): conn = con3() cursor = conn.cursor() cursor.execute(query) - habits = cursor.fetchone() + habits = cursor.fetchall() conn.close() - return habits \ No newline at end of file + return habits + + +def delete_habit(id: int): + query = f"DELETE FROM habits WHERE id = {id};" + conn = con3() + cursor = conn.cursor() + cursor.execute(query) + conn.commit() + conn.close() \ No newline at end of file