from dataclasses import dataclass from db.SQLiteClient import create_habit, get_habits, get_habit @dataclass class Habit: id: int name: str note: str times: int @staticmethod def create(name: str, times: int, note: str | None=None): id = create_habit(name, note, times) return Habit(id, name, note, times) @staticmethod def get(id: int): habit = get_habit(id) return Habit(habit[0], habit[1], habit[2], habit[3]) if habit else None @staticmethod def get_all(): raw_habits = get_habits() habits = [] for habit in raw_habits: habit = Habit(habit[0], habit[1], habit[2], habit[3]) habits.append(habit) return habits if habits else None