Finished Model methods for habit tracking and habit
This commit is contained in:
parent
1131995385
commit
eb8badd3ae
@ -140,6 +140,16 @@ def get_habitTrackings(id: int):
|
|||||||
return habit_tracking
|
return habit_tracking
|
||||||
|
|
||||||
|
|
||||||
|
def get_habitTrackings_by_habit_id(habit_id: int):
|
||||||
|
query = f"SELECT * FROM habit_trackings WHERE habit_id = {habit_id};"
|
||||||
|
conn = con3()
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute(query)
|
||||||
|
habit_trackings = cursor.fetchall()
|
||||||
|
conn.close()
|
||||||
|
return habit_trackings
|
||||||
|
|
||||||
|
|
||||||
def delete_habitTrackings(id: int):
|
def delete_habitTrackings(id: int):
|
||||||
query = f"DELETE FROM habit_trackings WHERE id = {id};"
|
query = f"DELETE FROM habit_trackings WHERE id = {id};"
|
||||||
conn = con3()
|
conn = con3()
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from db.SQLiteClient import create_habit, get_habit, delete_habit, get_next_slot
|
from db.SQLiteClient import create_habit, get_habit, delete_habit, get_next_slot, get_habitTrackings_by_habit_id
|
||||||
|
from models.HabitTrackings import HabitTrackings
|
||||||
|
from models.User import User
|
||||||
|
|
||||||
|
|
||||||
# Unit wird als Integers wie folgt gemessen:
|
# Unit wird als Integers wie folgt gemessen:
|
||||||
@ -32,3 +34,9 @@ class Habit:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def delete(id: int):
|
def delete(id: int):
|
||||||
delete_habit(id)
|
delete_habit(id)
|
||||||
|
|
||||||
|
def get_user(self):
|
||||||
|
return User.get(self.user_id)
|
||||||
|
|
||||||
|
def get_habitTrackings(self) -> list[HabitTrackings]:
|
||||||
|
return get_habitTrackings_by_habit_id(self.id)
|
||||||
|
|||||||
@ -18,6 +18,5 @@ class HabitTrackings:
|
|||||||
habitTrackings = get_habitTrackings(id)
|
habitTrackings = get_habitTrackings(id)
|
||||||
return HabitTrackings(habitTrackings[0], habitTrackings[1], habitTrackings[2]) if habitTrackings else None
|
return HabitTrackings(habitTrackings[0], habitTrackings[1], habitTrackings[2]) if habitTrackings else None
|
||||||
|
|
||||||
@staticmethod
|
def delete(self):
|
||||||
def delete(id: int):
|
delete_habitTrackings(self.id)
|
||||||
delete_habitTrackings(id)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user