Changed the List function to use project name instead of project id

This commit is contained in:
Dan
2024-05-04 19:35:01 -04:00
parent e8ce8575e8
commit 80becf1961
2 changed files with 13 additions and 2 deletions

View File

@ -72,13 +72,18 @@ class TaskCommands(app_commands.Group):
@app_commands.command(name="list", description="List tasks for a project.")
async def list_tasks(self, interaction: discord.Interaction, project_id: int):
try:
project_name = await get_project_name(project_id)
if not project_name:
await interaction.response.send_message(f"No project found with ID {project_id}.", ephemeral=True)
return
tasks = await list_tasks_for_project(project_id)
if tasks:
message = "\n".join([f"ID: {id}, Description: {description}, Assignee: {assignee}, Deadline: {deadline}, Status: {status}, Priority: {priority}"
for id, description, assignee, deadline, status, priority in tasks])
await interaction.response.send_message(f"Tasks for Project ID {project_id}:\n{message}")
await interaction.response.send_message(f"Tasks for Project '{project_name}':\n{message}")
else:
await interaction.response.send_message(f"No tasks found for project ID {project_id}.")
await interaction.response.send_message(f"No tasks found for project '{project_name}'.")
except Exception as e:
await interaction.response.send_message(f"Failed to retrieve tasks for project ID {project_id}.", ephemeral=True)
logger.error(f"Error in list_tasks: {e}")

View File

@ -36,6 +36,12 @@ async def get_project_id(name):
result = await cursor.fetchone()
return result[0] if result else None
async def get_project_name(project_id):
async with aiosqlite.connect(DATABASE) as db:
cursor = await db.execute("SELECT name FROM projects WHERE id = ?", (project_id,))
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