Fixed up the current commands. Added a logger. Added a catch-all

This commit is contained in:
Dan
2024-05-04 16:36:42 -04:00
parent 07ce578edf
commit 4599f49e84
3 changed files with 68 additions and 13 deletions

View File

@@ -7,13 +7,13 @@ async def init_db():
async with aiosqlite.connect(DATABASE) as db:
await db.execute(
'''CREATE TABLE IF NOT EXISTS projects(
id INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT UNIQUE,
description TEXT)'''
)
await db.execute(
'''CREATE TABLE IF NOT EXISTS tasks(
id INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY AUTOINCREMENT,
project_id INTEGER,
description TEXT,
assignee TEXT,
@@ -26,11 +26,28 @@ async def init_db():
async def add_project(name, description):
async with aiosqlite.connect(DATABASE) as db:
await db.execute("INSERT INTO projects(name, description) VALUES(?, ?)", (name, description))
cursor = await db.execute("INSERT INTO projects(name, description) VALUES(?, ?)", (name, description))
await db.commit()
return cursor.lastrowid # Returns the ID of the newly created project
async def get_project_id(name):
async with aiosqlite.connect(DATABASE) as db:
cursor = await db.execute("SELECT id FROM projects WHERE name = ?", (name,))
result = await cursor.fetchone()
return result[0] if result else None
async def add_task_to_project(project_id, description, assignee, deadline, status, priority):
async with aiosqlite.connect(DATABASE) as db:
# Change the date format to MM/DD/YYYY
deadline_date = datetime.strptime(deadline, "%m/%d/%Y").date()
await db.execute("INSERT INTO tasks(project_id, description, assignee, deadline, status, priority) VALUES(?, ?, ?, ?, ?, ?)",
(project_id, description, assignee, deadline_date, status, priority))
await db.commit()
async def add_task(project_id, description, assignee, deadline, status, priority):
async def update_task(task_id, description, assignee, deadline, status, priority):
async with aiosqlite.connect(DATABASE) as db:
deadline_date = datetime.strptime(deadline, "%Y-%m-%d").date()
await db.execute("INSERT INTO tasks(project_id, description, assignee, deadline, status, priority) VALUES(?, ?, ?, ?, ?, ?)", (project_id, description, assignee, deadline_date, status, priority))
# Change the date format to MM/DD/YYYY
deadline_date = datetime.strptime(deadline, "%m/%d/%Y").date()
await db.execute("UPDATE tasks SET description=?, assignee=?, deadline=?, status=?, priority=? WHERE id=?",
(description, assignee, deadline_date, status, priority, task_id))
await db.commit()