Compare commits
No commits in common. "e7d50f1eb82eab2687cc7ab5509383788b9bf8bd" and "3b0d68338e2d12059a45c1822b7f384d93be7014" have entirely different histories.
e7d50f1eb8
...
3b0d68338e
BIN
ER.png
BIN
ER.png
Binary file not shown.
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 37 KiB |
BIN
UML.png
BIN
UML.png
Binary file not shown.
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 20 KiB |
@ -41,10 +41,10 @@ def get_user_by_email(email: str):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def create_habit(name: str, user_id: int, times: int, unit: int, list_index: int, note: str | None=None):
|
def create_habit(name: str, user_id: int, times: int, unit: int, note: str | None=None):
|
||||||
now = datetime.now().isoformat()
|
now = datetime.now().isoformat()
|
||||||
query = (f"INSERT INTO habits (user_id, name, note, times, unit, list_index, created_at, updated_at) VALUES ('{user_id}', "
|
query = (f"INSERT INTO habits (user_id, name, note, times, unit, created_at, updated_at) VALUES ('{user_id}', "
|
||||||
f"'{name}', '{note}', '{times}', '{unit}', '{list_index}', '{now}', '{now}');")
|
f"'{name}', '{note}', '{times}', '{unit}', '{now}', '{now}');")
|
||||||
conn = con3()
|
conn = con3()
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|||||||
@ -1 +0,0 @@
|
|||||||
DROP TABLE habits;
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS habits
|
|
||||||
(
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
user_id INTEGER NOT NULL,
|
|
||||||
name TEXT NOT NULL,
|
|
||||||
note TEXT,
|
|
||||||
times INTEGER NOT NULL,
|
|
||||||
unit INTEGER,
|
|
||||||
list_index INTEGER NOT NULL,
|
|
||||||
created_at TEXT NOT NULL,
|
|
||||||
updated_at TEXT NOT NULL,
|
|
||||||
FOREIGN KEY (user_id) REFERENCES users(id)
|
|
||||||
);
|
|
||||||
@ -15,23 +15,22 @@ class Habit:
|
|||||||
note: str
|
note: str
|
||||||
times: int
|
times: int
|
||||||
unit: int
|
unit: int
|
||||||
list_index: int
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create(user_id: int, name: str, times: int, list_index: int, note: str | None=None, unit: int | None=1):
|
def create(user_id: int, name: str, times: int, unit: int, note: str | None=None):
|
||||||
id = create_habit(user_id, name, note, times, unit, list_index)
|
id = create_habit(user_id, name, note, times, unit)
|
||||||
return Habit(id, user_id, name, note, times, unit, list_index)
|
return Habit(id, user_id, name, note, times, unit)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get(id: int):
|
def get(id: int):
|
||||||
habit = get_habit(id)
|
habit = get_habit(id)
|
||||||
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6]) if habit else None
|
return Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5]) if habit else None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_all(user_id):
|
def get_all(user_id):
|
||||||
raw_habits = get_habits(user_id)
|
raw_habits = get_habits(user_id)
|
||||||
habits = []
|
habits = []
|
||||||
for habit in raw_habits:
|
for habit in raw_habits:
|
||||||
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5], habit[6])
|
habit = Habit(habit[0], habit[1], habit[2], habit[3], habit[4], habit[5])
|
||||||
habits.append(habit)
|
habits.append(habit)
|
||||||
return habits if habits else None
|
return habits if habits else None
|
||||||
Loading…
x
Reference in New Issue
Block a user