From db45e7f059a6e70531cc374b5b8d4c13e3a33311 Mon Sep 17 00:00:00 2001 From: Luis <75887681+Luis-Hamann@users.noreply.github.com> Date: Thu, 7 Mar 2024 18:28:06 +0100 Subject: [PATCH] added a way to accept shared habit_lists instead of directly accepting. accepted via habit_list.accept_List(habit_List.id, user.id) --- db/SQLiteClient.py | 9 +++++++++ models/HabitList.py | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index 2b6311a..c5bfc33 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -331,6 +331,15 @@ def add_user(list_id: int, user_id: int): conn.commit() conn.close() +def accept_List(list_id: int, user_id: int): + query = (f"UPDATE habit_users SET accepted = true WHERE {user_id} = habit_users.user_id AND {list_id} = habit_users.list_id;") + conn = con3() + cursor = conn.cursor() + cursor.execute(query) + conn.commit() + conn.close() + + def remove_user(list_id: int, user_id: int): query = f"DELETE FROM habit_lists WHERE user_id = {user_id} AND list_id = {list_id};" diff --git a/models/HabitList.py b/models/HabitList.py index ed90e8f..a77f3a1 100644 --- a/models/HabitList.py +++ b/models/HabitList.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from models.Habit import Habit from models.User import User from db.SQLiteClient import (create_habitList, get_habitList, get_habits, get_users, add_user, remove_user, - update_habitList, delete_habitList) + update_habitList, delete_habitList, accept_List) @dataclass @@ -66,6 +66,8 @@ class HabitList: else: return None + def accept_List(self, user:User): + accept_List(self.id, user.id) # Removes a User from the HabitList def remove_user(self, user_id):