35 lines
869 B
Python
35 lines
869 B
Python
from dataclasses import dataclass
|
|
from db.SQLiteClient import create_habit, get_habit, delete_habit, get_next_slot
|
|
|
|
|
|
# Unit wird als Integers wie folgt gemessen:
|
|
# 0: Tag
|
|
# 1: Woche (Default)
|
|
# 2: Monat
|
|
# 3: Jahr
|
|
|
|
@dataclass
|
|
class Habit:
|
|
id: int
|
|
user_id: int
|
|
name: str
|
|
note: str
|
|
times: int
|
|
unit: int
|
|
slot: int
|
|
|
|
@staticmethod
|
|
def create(user_id: int, name: str, times: int, note: str | None = None, unit: int | None = 1):
|
|
slot = get_next_slot()
|
|
id = create_habit(user_id, name, times, unit, slot, note)
|
|
return Habit(id, user_id, name, note, times, unit, slot)
|
|
|
|
@staticmethod
|
|
def get(id: int):
|
|
habit = get_habit(id)
|
|
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
|
|
|
@staticmethod
|
|
def delete(id: int):
|
|
delete_habit(id)
|