2024-01-13 13:30:29 +01:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
from db.SQLiteClient import create_habit, get_habits, get_habit
|
|
|
|
|
|
2024-01-16 10:58:25 +01:00
|
|
|
# Unit wird als Integers wie folgt gemessen:
|
|
|
|
|
# 0: Tag
|
|
|
|
|
# 1: Woche
|
|
|
|
|
# 2: Monal
|
|
|
|
|
# 3: Jahr
|
|
|
|
|
|
2024-01-13 13:30:29 +01:00
|
|
|
@dataclass
|
|
|
|
|
class Habit:
|
|
|
|
|
id: int
|
2024-01-16 10:58:25 +01:00
|
|
|
user_id: int
|
2024-01-13 13:30:29 +01:00
|
|
|
name: str
|
|
|
|
|
note: str
|
|
|
|
|
times: int
|
2024-01-16 10:58:25 +01:00
|
|
|
unit: int
|
2024-01-13 13:30:29 +01:00
|
|
|
|
|
|
|
|
@staticmethod
|
2024-01-16 10:58:25 +01:00
|
|
|
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)
|
2024-01-13 13:30:29 +01:00
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def get(id: int):
|
|
|
|
|
habit = get_habit(id)
|
2024-01-16 10:58:25 +01:00
|
|
|
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5]) if habit else None
|
2024-01-13 13:30:29 +01:00
|
|
|
|
|
|
|
|
@staticmethod
|
2024-01-16 11:10:54 +01:00
|
|
|
def get_all(user_id):
|
|
|
|
|
raw_habits = get_habits(user_id)
|
2024-01-13 13:30:29 +01:00
|
|
|
habits = []
|
|
|
|
|
for habit in raw_habits:
|
2024-01-16 10:58:25 +01:00
|
|
|
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5])
|
2024-01-13 13:30:29 +01:00
|
|
|
habits.append(habit)
|
|
|
|
|
return habits if habits else None
|