diff --git a/app.py b/app.py index 8219acc..006dbaf 100644 --- a/app.py +++ b/app.py @@ -4,8 +4,8 @@ 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 models.Habit import Habit from utils import anonymous_required # Create a new Flask instance diff --git a/models/Habit.py b/models/Habit.py index 7d0f065..d65be2b 100644 --- a/models/Habit.py +++ b/models/Habit.py @@ -1,5 +1,6 @@ from dataclasses import dataclass -from db.SQLiteClient import create_habit, get_habits, get_habit +from db.SQLiteClient import create_habit, get_habit, delete_habit + # Unit wird als Integers wie folgt gemessen: # 0: Tag @@ -28,10 +29,5 @@ class Habit: 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[6]) - habits.append(habit) - return habits if habits else None + def delete(id: int): + delete_habit(id) diff --git a/models/User.py b/models/User.py index 353f624..6ac4891 100644 --- a/models/User.py +++ b/models/User.py @@ -1,5 +1,6 @@ from flask_login import UserMixin -from db.SQLiteClient import create_user, get_user, get_user_by_email +from db.SQLiteClient import create_user, get_user, get_user_by_email, get_habits, delete_user +from models.Habit import Habit class User(UserMixin): @@ -23,3 +24,15 @@ class User(UserMixin): def get_by_email(email: str): user = get_user_by_email(email) return User(user[0], user[1], user[2], user[3]) if user else None + + @staticmethod + def delete(id: id): + delete_user(id) + + def get_habits(self): + raw_habits = get_habits(self.id) + habits = [] + for habit in raw_habits: + 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