Compare commits

..

2 Commits

Author SHA1 Message Date
Yapollon
52ba6988fd Merge remote-tracking branch 'origin/master' 2024-01-17 11:23:41 +01:00
Yapollon
cc8f2f56a1 Fixed get_all()
and added delete methods for user and habits
2024-01-17 11:23:22 +01:00
2 changed files with 25 additions and 5 deletions

2
app.py
View File

@ -142,4 +142,4 @@ def logout():
# Run the application # Run the application
if __name__ == '__main__': if __name__ == '__main__':
app.run(port=5000, debug=True) app.run(port=5000, debug=True)

View File

@ -41,6 +41,17 @@ def get_user_by_email(email: str):
return user 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): def create_habit(name: str, user_id: int, times: int, unit: int, slot: int, note: str | None=None):
now = datetime.now().isoformat() now = datetime.now().isoformat()
query = (f"INSERT INTO habits (user_id, name, note, times, unit, list_index, created_at, updated_at) VALUES ('{user_id}', " 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() conn = con3()
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(query) cursor.execute(query)
habits = cursor.fetchone() habit = cursor.fetchone()
conn.close() conn.close()
return habits return habit
def get_habits(user_id: int): def get_habits(user_id: int):
@ -68,6 +79,15 @@ def get_habits(user_id: int):
conn = con3() conn = con3()
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(query) cursor.execute(query)
habits = cursor.fetchone() habits = cursor.fetchall()
conn.close() conn.close()
return habits 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()