27 lines
798 B
Python
27 lines
798 B
Python
|
|
from datetime import date, datetime
|
||
|
|
from dataclasses import dataclass
|
||
|
|
from db.SQLiteClient import create_habitTracking, get_habitTracking, delete_habitTracking
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class HabitTracking:
|
||
|
|
id: int
|
||
|
|
habit_id: int
|
||
|
|
created_at: date
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def create(habit_id: int):
|
||
|
|
id = create_habitTracking(habit_id)
|
||
|
|
return HabitTracking(id, habit_id, datetime.now())
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def get(id: int):
|
||
|
|
habitTrackings = get_habitTracking(id)
|
||
|
|
return HabitTracking(habitTrackings[0], habitTrackings[1],
|
||
|
|
datetime.strptime(habitTrackings[2], "%Y-%m-%dT%H:%M:%S.%f")) \
|
||
|
|
if habitTrackings else None
|
||
|
|
|
||
|
|
# Deletes the HabitTracking
|
||
|
|
def delete(self):
|
||
|
|
delete_habitTracking(self.id)
|