Yapollon 0d80cdcf9b Deletes are now functional for both User and Habit
Also changed get_habits from the Habit class to the User class
2024-01-17 11:46:07 +01:00

38 lines
1.2 KiB
Python

from flask_login import UserMixin
from db.SQLiteClient import create_user, get_user, get_user_by_email, get_habits, delete_user
from models.Habit import Habit
class User(UserMixin):
def __init__(self, id: int, name: str, email: str, password: str | None = None):
self.id = id
self.name = name
self.email = email
self.password = password
@staticmethod
def create(name: str, email: str, password: str):
id = create_user(name, email, password)
return User(id, name, email)
@staticmethod
def get(id: int):
user = get_user(id)
return User(user[0], user[1], user[2], user[3]) if user else None
@staticmethod
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