diff --git a/ER.dia b/ER.dia index 1387809..defdcfd 100644 Binary files a/ER.dia and b/ER.dia differ diff --git a/ER.png b/ER.png index eb83e0a..b597642 100644 Binary files a/ER.png and b/ER.png differ diff --git a/UML.dia b/UML.dia index 3926aef..e1482bd 100644 Binary files a/UML.dia and b/UML.dia differ diff --git a/UML.png b/UML.png index 7e31f69..c8d8263 100644 Binary files a/UML.png and b/UML.png differ diff --git a/db/SQLiteClient.py b/db/SQLiteClient.py index a52d109..2012ecf 100644 --- a/db/SQLiteClient.py +++ b/db/SQLiteClient.py @@ -41,10 +41,10 @@ def get_user_by_email(email: str): return user -def create_habit(name: str, user_id: int, times: int, unit: int, note: str | None=None): +def create_habit(name: str, user_id: int, times: int, unit: int, list_index: int, note: str | None=None): now = datetime.now().isoformat() - query = (f"INSERT INTO habits (user_id, name, note, times, unit, created_at, updated_at) VALUES ('{user_id}', " - f"'{name}', '{note}', '{times}', '{unit}', '{now}', '{now}');") + query = (f"INSERT INTO habits (user_id, name, note, times, unit, list_index, created_at, updated_at) VALUES ('{user_id}', " + f"'{name}', '{note}', '{times}', '{unit}', '{list_index}', '{now}', '{now}');") conn = con3() cursor = conn.cursor() cursor.execute(query) diff --git a/db/migrations/1705400256_delete_habits_table.sql b/db/migrations/1705400256_delete_habits_table.sql new file mode 100644 index 0000000..8d667a0 --- /dev/null +++ b/db/migrations/1705400256_delete_habits_table.sql @@ -0,0 +1 @@ +DROP TABLE habits; diff --git a/db/migrations/1705400283_create_habits_table.sql b/db/migrations/1705400283_create_habits_table.sql new file mode 100644 index 0000000..31c8272 --- /dev/null +++ b/db/migrations/1705400283_create_habits_table.sql @@ -0,0 +1,13 @@ +CREATE TABLE IF NOT EXISTS habits +( + id INTEGER PRIMARY KEY AUTOINCREMENT, + user_id INTEGER NOT NULL, + name TEXT NOT NULL, + note TEXT, + times INTEGER NOT NULL, + unit INTEGER, + list_index INTEGER NOT NULL, + created_at TEXT NOT NULL, + updated_at TEXT NOT NULL, + FOREIGN KEY (user_id) REFERENCES users(id) +); \ No newline at end of file diff --git a/models/Habit.py b/models/Habit.py index 5c3d6fb..e5a9c8a 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -15,22 +15,23 @@ class Habit: note: str times: int unit: int + list_index: int @staticmethod - def create(user_id: int, name: str, times: int, unit: int, note: str | None=None): - id = create_habit(user_id, name, note, times, unit) - return Habit(id, user_id, name, note, times, unit) + def create(user_id: int, name: str, times: int, list_index: int, note: str | None=None, unit: int | None=1): + id = create_habit(user_id, name, note, times, unit, list_index) + return Habit(id, user_id, name, note, times, unit, list_index) @staticmethod def get(id: int): habit = get_habit(id) - return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5]) if habit else None + return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None @staticmethod def get_all(user_id): raw_habits = get_habits(user_id) habits = [] for habit in raw_habits: - habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5]) + habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) habits.append(habit) return habits if habits else None \ No newline at end of file