From e3c5316caa907f46ce9f5d7fef47ba1160ec5af4 Mon Sep 17 00:00:00 2001 From: vhespanha Date: Sat, 17 Aug 2024 20:22:42 -0300 Subject: [PATCH] Revert "First implementation of subprojects and subtasks, needs testing" This reverts commit d1714e646f61e55ff7d69ca9bde9f81eca5bd16c. Revert main to previous state (before sub-tasks and sub-proj) --- cmd/edit.go | 26 ------ cmd/list.go | 156 ++++++++------------------------- cmd/new.go | 75 +++++----------- cmd/remove.go | 26 ++---- cmd/toggle.go | 13 +-- pkg/models/project.go | 1 - pkg/models/task.go | 1 - pkg/repository/project_repo.go | 68 +++----------- pkg/repository/repository.go | 6 +- pkg/repository/task_repo.go | 50 ++--------- 10 files changed, 88 insertions(+), 334 deletions(-) diff --git a/cmd/edit.go b/cmd/edit.go index e3a95a3..3367f4a 100644 --- a/cmd/edit.go +++ b/cmd/edit.go @@ -49,8 +49,6 @@ func init() { editCmd.Flags().StringP("name", "n", "", "New name") editCmd.Flags().StringP("description", "d", "", "New description") - editCmd.Flags().StringP("project", "p", "", "New parent project name or ID") - editCmd.Flags().StringP("task", "t", "", "New parent task ID for subtasks") editCmd.Flags().StringP("due", "D", "", "New due date for task (format: YYYY-MM-DD HH:MM)") editCmd.Flags(). IntP("priority", "r", 0, "New priority for task (1: High, 2: Medium, 3: Low, 4: None)") @@ -65,7 +63,6 @@ func editProject(cmd *cobra.Command, repo *repository.Repository, id int) { name, _ := cmd.Flags().GetString("name") description, _ := cmd.Flags().GetString("description") - parentProjectIdentifier, _ := cmd.Flags().GetString("project") if name != "" { project.Name = name @@ -73,19 +70,6 @@ func editProject(cmd *cobra.Command, repo *repository.Repository, id int) { if description != "" { project.Description = description } - if parentProjectIdentifier != "" { - if utils.IsNumeric(parentProjectIdentifier) { - parentID, _ := strconv.Atoi(parentProjectIdentifier) - project.ParentProjectId = &parentID - } else { - parentProject, err := repo.GetProjectByName(parentProjectIdentifier) - if err != nil || parentProject == nil { - fmt.Printf("Parent project '%s' not found.\n", parentProjectIdentifier) - return - } - project.ParentProjectId = &parentProject.ID - } - } err = repo.UpdateProject(project) if err != nil { @@ -107,7 +91,6 @@ func editTask(cmd *cobra.Command, repo *repository.Repository, id int) { description, _ := cmd.Flags().GetString("description") dueDateStr, _ := cmd.Flags().GetString("due") priority, _ := cmd.Flags().GetInt("priority") - parentTaskIdentifier, _ := cmd.Flags().GetString("task") if name != "" { task.Name = name @@ -130,15 +113,6 @@ func editTask(cmd *cobra.Command, repo *repository.Repository, id int) { fmt.Println("Invalid priority. Keeping the existing priority.") } } - if parentTaskIdentifier != "" { - if utils.IsNumeric(parentTaskIdentifier) { - parentID, _ := strconv.Atoi(parentTaskIdentifier) - task.ParentTaskId = &parentID - } else { - fmt.Println("Parent task must be identified by a numeric ID.") - return - } - } err = repo.UpdateTask(task) if err != nil { diff --git a/cmd/list.go b/cmd/list.go index 979d199..aae0bc7 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "strconv" - "strings" "github.com/d4r1us-drk/clido/pkg/models" "github.com/d4r1us-drk/clido/pkg/repository" @@ -32,14 +31,13 @@ var listCmd = &cobra.Command{ defer repo.Close() outputJSON, _ := cmd.Flags().GetBool("json") - treeView, _ := cmd.Flags().GetBool("tree") switch args[0] { case "projects": - listProjects(repo, outputJSON, treeView) + listProjects(repo, outputJSON) case "tasks": projectFilter, _ := cmd.Flags().GetString("project") - listTasks(repo, projectFilter, outputJSON, treeView) + listTasks(repo, projectFilter, outputJSON) default: fmt.Println("Invalid option. Use 'list projects' or 'list tasks'.") } @@ -50,10 +48,9 @@ func init() { rootCmd.AddCommand(listCmd) listCmd.Flags().StringP("project", "p", "", "Filter tasks by project name or ID") listCmd.Flags().BoolP("json", "j", false, "Output list in JSON format") - listCmd.Flags().BoolP("tree", "t", false, "Display projects or tasks in a tree-like structure") } -func listProjects(repo *repository.Repository, outputJSON bool, treeView bool) { +func listProjects(repo *repository.Repository, outputJSON bool) { projects, err := repo.GetAllProjects() if err != nil { fmt.Printf("Error listing projects: %v\n", err) @@ -67,14 +64,25 @@ func listProjects(repo *repository.Repository, outputJSON bool, treeView bool) { return } fmt.Println(string(jsonData)) - } else if treeView { - printProjectTree(repo, projects, nil, 0) } else { - printProjectTable(repo, projects) + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader([]string{"ID", "Name", "Description"}) + table.SetRowLine(true) + + for _, project := range projects { + table.Append([]string{ + strconv.Itoa(project.ID), + utils.WrapText(project.Name, 30), + utils.WrapText(project.Description, 50), + }) + } + + fmt.Println("Projects:") + table.Render() } } -func listTasks(repo *repository.Repository, projectFilter string, outputJSON bool, treeView bool) { +func listTasks(repo *repository.Repository, projectFilter string, outputJSON bool) { var tasks []*models.Task var err error @@ -120,120 +128,32 @@ func listTasks(repo *repository.Repository, projectFilter string, outputJSON boo return } fmt.Println(string(jsonData)) - } else if treeView { - printTaskTree(repo, tasks, nil, 0) } else { - printTaskTable(repo, tasks) - } -} - -func printProjectTable(repo *repository.Repository, projects []*models.Project) { - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{"ID", "Name", "Description", "Type", "Child Of"}) - table.SetRowLine(true) - - for _, project := range projects { - typeField := "Parent" - parentChildField := "None" - if project.ParentProjectId != nil { - typeField = "Child" - parentProject, _ := repo.GetProjectByID(*project.ParentProjectId) - if parentProject != nil { - parentChildField = parentProject.Name - } - } else { - subprojects, _ := repo.GetSubprojects(project.ID) - if len(subprojects) > 0 { - typeField = "Parent" - } - } - - table.Append([]string{ - strconv.Itoa(project.ID), - utils.WrapText(project.Name, 30), - utils.WrapText(project.Description, 50), - typeField, - parentChildField, + table := tablewriter.NewWriter(os.Stdout) + table.SetHeader([]string{ + "ID", "Name", "Description", "Due Date", "Completed", "Past Due", "Priority", "Project", }) - } + table.SetRowLine(true) - fmt.Println("Projects:") - table.Render() -} - -func printTaskTable(repo *repository.Repository, tasks []*models.Task) { - table := tablewriter.NewWriter(os.Stdout) - table.SetHeader([]string{ - "ID", "Name", "Description", "Due Date", "Completed", "Past Due", "Priority", "Project", "Type", "Parent/Child Of", - }) - table.SetRowLine(true) - - for _, task := range tasks { - typeField := "Parent" - parentChildField := "None" - if task.ParentTaskId != nil { - typeField = "Child" - parentTask, _ := repo.GetTaskByID(*task.ParentTaskId) - if parentTask != nil { - parentChildField = parentTask.Name + for _, task := range tasks { + project, _ := repo.GetProjectByID(task.ProjectID) + projectName := "" + if project != nil { + projectName = project.Name } - } else { - subtasks, _ := repo.GetSubtasks(task.ID) - if len(subtasks) > 0 { - typeField = "Parent" - } - } - - project, _ := repo.GetProjectByID(task.ProjectID) - projectName := "" - if project != nil { - projectName = project.Name - } - - table.Append([]string{ - strconv.Itoa(task.ID), - utils.WrapText(task.Name, 20), - utils.WrapText(task.Description, 30), - utils.FormatDate(task.DueDate), - fmt.Sprintf("%v", task.TaskCompleted), - utils.ColoredPastDue(task.DueDate, task.TaskCompleted), - utils.GetPriorityString(task.Priority), - utils.WrapText(projectName, 20), - typeField, - parentChildField, - }) - } - table.Render() -} - -func printProjectTree(repo *repository.Repository, projects []*models.Project, parentID *int, level int) { - indent := strings.Repeat("│ ", level) - for i, project := range projects { - if (parentID == nil && project.ParentProjectId == nil) || (parentID != nil && project.ParentProjectId != nil && *project.ParentProjectId == *parentID) { - prefix := "├──" - if i == len(projects)-1 { - prefix = "└──" - } - fmt.Printf("%s%s %s (ID: %d)\n", indent, prefix, project.Name, project.ID) - printProjectTree(repo, projects, &project.ID, level+1) + table.Append([]string{ + strconv.Itoa(task.ID), + utils.WrapText(task.Name, 20), + utils.WrapText(task.Description, 30), + utils.FormatDate(task.DueDate), + fmt.Sprintf("%v", task.TaskCompleted), + utils.ColoredPastDue(task.DueDate, task.TaskCompleted), + utils.GetPriorityString(task.Priority), + utils.WrapText(projectName, 20), + }) } - } -} -func printTaskTree(repo *repository.Repository, tasks []*models.Task, parentID *int, level int) { - indent := strings.Repeat("│ ", level) - for i, task := range tasks { - if (parentID == nil && task.ParentTaskId == nil) || (parentID != nil && task.ParentTaskId != nil && *task.ParentTaskId == *parentID) { - prefix := "├──" - if i == len(tasks)-1 { - prefix = "└──" - } - fmt.Printf("%s%s %s (ID: %d)\n", indent, prefix, task.Name, task.ID) - fmt.Printf("%s Description: %s\n", indent, task.Description) - fmt.Printf("%s Due Date: %s, Completed: %v, Priority: %s\n", - indent, utils.FormatDate(task.DueDate), task.TaskCompleted, utils.GetPriorityString(task.Priority)) - printTaskTree(repo, tasks, &task.ID, level+1) - } + table.Render() } } diff --git a/cmd/new.go b/cmd/new.go index 9a39cf9..34e63ec 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -44,8 +44,7 @@ func init() { newCmd.Flags().StringP("name", "n", "", "Name of the project or task") newCmd.Flags().StringP("description", "d", "", "Description of the project or task") - newCmd.Flags().StringP("project", "p", "", "Parent project name or ID for subprojects or tasks") - newCmd.Flags().StringP("task", "t", "", "Parent task ID for subtasks") + newCmd.Flags().StringP("project", "p", "", "Project name or ID for the task") newCmd.Flags().StringP("due", "D", "", "Due date for the task (format: YYYY-MM-DD HH:MM)") newCmd.Flags(). IntP("priority", "r", 4, "Priority of the task (1: High, 2: Medium, 3: Low, 4: None)") @@ -54,32 +53,15 @@ func init() { func createProject(cmd *cobra.Command, repo *repository.Repository) { name, _ := cmd.Flags().GetString("name") description, _ := cmd.Flags().GetString("description") - parentProjectIdentifier, _ := cmd.Flags().GetString("project") if name == "" { fmt.Println("Project name is required.") return } - var parentProjectID *int - if parentProjectIdentifier != "" { - if utils.IsNumeric(parentProjectIdentifier) { - id, _ := strconv.Atoi(parentProjectIdentifier) - parentProjectID = &id - } else { - parentProject, err := repo.GetProjectByName(parentProjectIdentifier) - if err != nil || parentProject == nil { - fmt.Printf("Parent project '%s' not found.\n", parentProjectIdentifier) - return - } - parentProjectID = &parentProject.ID - } - } - project := &models.Project{ - Name: name, - Description: description, - ParentProjectId: parentProjectID, + Name: name, + Description: description, } err := repo.CreateProject(project) @@ -95,43 +77,27 @@ func createTask(cmd *cobra.Command, repo *repository.Repository) { name, _ := cmd.Flags().GetString("name") description, _ := cmd.Flags().GetString("description") projectIdentifier, _ := cmd.Flags().GetString("project") - parentTaskIdentifier, _ := cmd.Flags().GetString("task") dueDateStr, _ := cmd.Flags().GetString("due") priority, _ := cmd.Flags().GetInt("priority") - if name == "" { - fmt.Println("Task name is required.") + if name == "" || projectIdentifier == "" { + fmt.Println("Task name and project identifier are required.") return } - var projectID int - var parentTaskID *int + var project *models.Project + var err error - if projectIdentifier != "" { - if utils.IsNumeric(projectIdentifier) { - id, _ := strconv.Atoi(projectIdentifier) - projectID = id - } else { - project, err := repo.GetProjectByName(projectIdentifier) - if err != nil || project == nil { - fmt.Printf("Project '%s' not found.\n", projectIdentifier) - return - } - projectID = project.ID - } + if utils.IsNumeric(projectIdentifier) { + projectID, _ := strconv.Atoi(projectIdentifier) + project, err = repo.GetProjectByID(projectID) } else { - fmt.Println("Task must be associated with a project.") - return + project, err = repo.GetProjectByName(projectIdentifier) } - if parentTaskIdentifier != "" { - if utils.IsNumeric(parentTaskIdentifier) { - id, _ := strconv.Atoi(parentTaskIdentifier) - parentTaskID = &id - } else { - fmt.Println("Parent task must be identified by a numeric ID.") - return - } + if err != nil || project == nil { + fmt.Printf("Project '%s' not found.\n", projectIdentifier) + return } var dueDate *time.Time @@ -145,15 +111,14 @@ func createTask(cmd *cobra.Command, repo *repository.Repository) { } task := &models.Task{ - Name: name, - Description: description, - ProjectID: projectID, - DueDate: dueDate, - Priority: priority, - ParentTaskId: parentTaskID, + Name: name, + Description: description, + ProjectID: project.ID, + DueDate: dueDate, + Priority: priority, } - err := repo.CreateTask(task) + err = repo.CreateTask(task) if err != nil { fmt.Printf("Error creating task: %v\n", err) return diff --git a/cmd/remove.go b/cmd/remove.go index 83ba7cb..23c050d 100644 --- a/cmd/remove.go +++ b/cmd/remove.go @@ -10,8 +10,8 @@ import ( var removeCmd = &cobra.Command{ Use: "remove [project|task] ", - Short: "Remove a project or task along with all its subprojects or subtasks", - Long: `Remove an existing project or task identified by its ID. This will also remove all associated subprojects or subtasks.`, + Short: "Remove a project or task", + Long: `Remove an existing project or task identified by its ID.`, Run: func(cmd *cobra.Command, args []string) { if len(args) < 2 { fmt.Println("Insufficient arguments. Use 'remove project ' or 'remove task '.") @@ -47,43 +47,33 @@ func init() { } func removeProject(repo *repository.Repository, id int) { - // First remove all subprojects - subprojects, err := repo.GetSubprojects(id) + project, err := repo.GetProjectByID(id) if err != nil { - fmt.Printf("Error retrieving subprojects: %v\n", err) + fmt.Printf("Error retrieving project: %v\n", err) return } - for _, subproject := range subprojects { - removeProject(repo, subproject.ID) - } - // Now remove the parent project err = repo.DeleteProject(id) if err != nil { fmt.Printf("Error removing project: %v\n", err) return } - fmt.Printf("Project (ID: %d) and all its subprojects removed successfully.\n", id) + fmt.Printf("Project '%s' (ID: %d) removed successfully.\n", project.Name, id) } func removeTask(repo *repository.Repository, id int) { - // First remove all subtasks - subtasks, err := repo.GetSubtasks(id) + task, err := repo.GetTaskByID(id) if err != nil { - fmt.Printf("Error retrieving subtasks: %v\n", err) + fmt.Printf("Error retrieving task: %v\n", err) return } - for _, subtask := range subtasks { - removeTask(repo, subtask.ID) - } - // Now remove the parent task err = repo.DeleteTask(id) if err != nil { fmt.Printf("Error removing task: %v\n", err) return } - fmt.Printf("Task (ID: %d) and all its subtasks removed successfully.\n", id) + fmt.Printf("Task '%s' (ID: %d) removed successfully.\n", task.Name, id) } diff --git a/cmd/toggle.go b/cmd/toggle.go index b1198cd..48820e0 100644 --- a/cmd/toggle.go +++ b/cmd/toggle.go @@ -32,17 +32,15 @@ var toggleCmd = &cobra.Command{ return } - recursive, _ := cmd.Flags().GetBool("recursive") - toggleTask(repo, id, recursive) + toggleTask(repo, id) }, } func init() { rootCmd.AddCommand(toggleCmd) - toggleCmd.Flags().BoolP("recursive", "r", false, "Recursively toggle subtasks") } -func toggleTask(repo *repository.Repository, id int, recursive bool) { +func toggleTask(repo *repository.Repository, id int) { task, err := repo.GetTaskByID(id) if err != nil { fmt.Printf("Error retrieving task: %v\n", err) @@ -70,11 +68,4 @@ func toggleTask(repo *repository.Repository, id int, recursive bool) { } fmt.Printf("Task '%s' (ID: %d) marked as %s.\n", task.Name, id, status) - - if recursive { - subtasks, _ := repo.GetSubtasks(id) - for _, subtask := range subtasks { - toggleTask(repo, subtask.ID, recursive) - } - } } diff --git a/pkg/models/project.go b/pkg/models/project.go index 8d00b34..351b562 100644 --- a/pkg/models/project.go +++ b/pkg/models/project.go @@ -8,5 +8,4 @@ type Project struct { Description string CreationDate time.Time LastModifiedDate time.Time - ParentProjectId *int } diff --git a/pkg/models/task.go b/pkg/models/task.go index a634515..5b230de 100644 --- a/pkg/models/task.go +++ b/pkg/models/task.go @@ -13,5 +13,4 @@ type Task struct { CreationDate time.Time LastUpdatedDate time.Time Priority int - ParentTaskId *int } diff --git a/pkg/repository/project_repo.go b/pkg/repository/project_repo.go index 11d5e10..d624cdd 100644 --- a/pkg/repository/project_repo.go +++ b/pkg/repository/project_repo.go @@ -9,40 +9,29 @@ import ( func (r *Repository) CreateProject(project *models.Project) error { project.CreationDate = time.Now() project.LastModifiedDate = time.Now() - - // Find the lowest unused ID - var id int - err := r.db.QueryRow(` - SELECT COALESCE(MIN(p1.ID + 1), 1) - FROM Projects p1 - LEFT JOIN Projects p2 ON p1.ID + 1 = p2.ID - WHERE p2.ID IS NULL`).Scan(&id) - if err != nil { - return err - } - - // Insert the project with the found ID - _, err = r.db.Exec( - `INSERT INTO Projects (ID, Name, Description, CreationDate, LastModifiedDate, ParentProjectId) VALUES (?, ?, ?, ?, ?, ?)`, - id, + result, err := r.db.Exec( + `INSERT INTO Projects (Name, Description, CreationDate, LastModifiedDate) VALUES (?, ?, ?, ?)`, project.Name, project.Description, project.CreationDate, project.LastModifiedDate, - project.ParentProjectId, ) if err != nil { return err } - project.ID = id + id, err := result.LastInsertId() + if err != nil { + return err + } + project.ID = int(id) return nil } func (r *Repository) GetProjectByID(id int) (*models.Project, error) { project := &models.Project{} - err := r.db.QueryRow(`SELECT ID, Name, Description, CreationDate, LastModifiedDate, ParentProjectId FROM Projects WHERE ID = ?`, id). - Scan(&project.ID, &project.Name, &project.Description, &project.CreationDate, &project.LastModifiedDate, &project.ParentProjectId) + err := r.db.QueryRow(`SELECT ID, Name, Description, CreationDate, LastModifiedDate FROM Projects WHERE ID = ?`, id). + Scan(&project.ID, &project.Name, &project.Description, &project.CreationDate, &project.LastModifiedDate) if err != nil { return nil, err } @@ -51,8 +40,8 @@ func (r *Repository) GetProjectByID(id int) (*models.Project, error) { func (r *Repository) GetProjectByName(name string) (*models.Project, error) { project := &models.Project{} - err := r.db.QueryRow(`SELECT ID, Name, Description, CreationDate, LastModifiedDate, ParentProjectId FROM Projects WHERE Name = ?`, name). - Scan(&project.ID, &project.Name, &project.Description, &project.CreationDate, &project.LastModifiedDate, &project.ParentProjectId) + err := r.db.QueryRow(`SELECT ID, Name, Description, CreationDate, LastModifiedDate FROM Projects WHERE Name = ?`, name). + Scan(&project.ID, &project.Name, &project.Description, &project.CreationDate, &project.LastModifiedDate) if err != nil { return nil, err } @@ -61,36 +50,7 @@ func (r *Repository) GetProjectByName(name string) (*models.Project, error) { func (r *Repository) GetAllProjects() ([]*models.Project, error) { rows, err := r.db.Query( - `SELECT ID, Name, Description, CreationDate, LastModifiedDate, ParentProjectId FROM Projects`, - ) - if err != nil { - return nil, err - } - defer rows.Close() - - var projects []*models.Project - for rows.Next() { - project := &models.Project{} - err := rows.Scan( - &project.ID, - &project.Name, - &project.Description, - &project.CreationDate, - &project.LastModifiedDate, - &project.ParentProjectId, - ) - if err != nil { - return nil, err - } - projects = append(projects, project) - } - return projects, nil -} - -func (r *Repository) GetSubprojects(parentProjectID int) ([]*models.Project, error) { - rows, err := r.db.Query( - `SELECT ID, Name, Description, CreationDate, LastModifiedDate, ParentProjectId FROM Projects WHERE ParentProjectId = ?`, - parentProjectID, + `SELECT ID, Name, Description, CreationDate, LastModifiedDate FROM Projects`, ) if err != nil { return nil, err @@ -106,7 +66,6 @@ func (r *Repository) GetSubprojects(parentProjectID int) ([]*models.Project, err &project.Description, &project.CreationDate, &project.LastModifiedDate, - &project.ParentProjectId, ) if err != nil { return nil, err @@ -119,11 +78,10 @@ func (r *Repository) GetSubprojects(parentProjectID int) ([]*models.Project, err func (r *Repository) UpdateProject(project *models.Project) error { project.LastModifiedDate = time.Now() _, err := r.db.Exec( - `UPDATE Projects SET Name = ?, Description = ?, LastModifiedDate = ?, ParentProjectId = ? WHERE ID = ?`, + `UPDATE Projects SET Name = ?, Description = ?, LastModifiedDate = ? WHERE ID = ?`, project.Name, project.Description, project.LastModifiedDate, - project.ParentProjectId, project.ID, ) return err diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index a0228cf..06eb028 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -57,9 +57,7 @@ func (r *Repository) init() error { Name TEXT NOT NULL UNIQUE, Description TEXT, CreationDate DATETIME NOT NULL, - LastModifiedDate DATETIME NOT NULL, - ParentProjectId INTEGER, - FOREIGN KEY (ParentProjectID) REFERENCES Projects(ID) + LastModifiedDate DATETIME NOT NULL );` createTaskTable := ` @@ -74,8 +72,6 @@ func (r *Repository) init() error { CreationDate DATETIME NOT NULL, LastUpdatedDate DATETIME NOT NULL, Priority INTEGER NOT NULL DEFAULT 4, - ParentTaskId INTEGER, - FOREIGN KEY (ParentTaskId) REFERENCES Tasks(ID), FOREIGN KEY (ProjectID) REFERENCES Projects(ID) );` diff --git a/pkg/repository/task_repo.go b/pkg/repository/task_repo.go index f50e57b..0a56392 100644 --- a/pkg/repository/task_repo.go +++ b/pkg/repository/task_repo.go @@ -23,7 +23,7 @@ func (r *Repository) CreateTask(task *models.Task) error { // Insert the task with the found ID _, err = r.db.Exec( - `INSERT INTO Tasks (ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority, ParentTaskId) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + `INSERT INTO Tasks (ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, id, task.Name, task.Description, @@ -34,7 +34,6 @@ func (r *Repository) CreateTask(task *models.Task) error { task.CreationDate, task.LastUpdatedDate, task.Priority, - task.ParentTaskId, ) if err != nil { return err @@ -46,8 +45,8 @@ func (r *Repository) CreateTask(task *models.Task) error { func (r *Repository) GetTaskByID(id int) (*models.Task, error) { task := &models.Task{} - err := r.db.QueryRow(`SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority, ParentTaskId FROM Tasks WHERE ID = ?`, id). - Scan(&task.ID, &task.Name, &task.Description, &task.ProjectID, &task.TaskCompleted, &task.DueDate, &task.CompletionDate, &task.CreationDate, &task.LastUpdatedDate, &task.Priority, &task.ParentTaskId) + err := r.db.QueryRow(`SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority FROM Tasks WHERE ID = ?`, id). + Scan(&task.ID, &task.Name, &task.Description, &task.ProjectID, &task.TaskCompleted, &task.DueDate, &task.CompletionDate, &task.CreationDate, &task.LastUpdatedDate, &task.Priority) if err != nil { return nil, err } @@ -56,7 +55,7 @@ func (r *Repository) GetTaskByID(id int) (*models.Task, error) { func (r *Repository) GetAllTasks() ([]*models.Task, error) { rows, err := r.db.Query( - `SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority, ParentTaskId FROM Tasks`, + `SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority FROM Tasks`, ) if err != nil { return nil, err @@ -77,7 +76,6 @@ func (r *Repository) GetAllTasks() ([]*models.Task, error) { &task.CreationDate, &task.LastUpdatedDate, &task.Priority, - &task.ParentTaskId, ) if err != nil { return nil, err @@ -89,7 +87,7 @@ func (r *Repository) GetAllTasks() ([]*models.Task, error) { func (r *Repository) GetTasksByProjectID(projectID int) ([]*models.Task, error) { rows, err := r.db.Query( - `SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority, ParentTaskId FROM Tasks WHERE ProjectID = ?`, + `SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority FROM Tasks WHERE ProjectID = ?`, projectID, ) if err != nil { @@ -111,41 +109,6 @@ func (r *Repository) GetTasksByProjectID(projectID int) ([]*models.Task, error) &task.CreationDate, &task.LastUpdatedDate, &task.Priority, - &task.ParentTaskId, - ) - if err != nil { - return nil, err - } - tasks = append(tasks, task) - } - return tasks, nil -} - -func (r *Repository) GetSubtasks(parentTaskID int) ([]*models.Task, error) { - rows, err := r.db.Query( - `SELECT ID, Name, Description, ProjectID, TaskCompleted, DueDate, CompletionDate, CreationDate, LastUpdatedDate, Priority, ParentTaskId FROM Tasks WHERE ParentTaskId = ?`, - parentTaskID, - ) - if err != nil { - return nil, err - } - defer rows.Close() - - var tasks []*models.Task - for rows.Next() { - task := &models.Task{} - err := rows.Scan( - &task.ID, - &task.Name, - &task.Description, - &task.ProjectID, - &task.TaskCompleted, - &task.DueDate, - &task.CompletionDate, - &task.CreationDate, - &task.LastUpdatedDate, - &task.Priority, - &task.ParentTaskId, ) if err != nil { return nil, err @@ -158,7 +121,7 @@ func (r *Repository) GetSubtasks(parentTaskID int) ([]*models.Task, error) { func (r *Repository) UpdateTask(task *models.Task) error { task.LastUpdatedDate = time.Now() _, err := r.db.Exec( - `UPDATE Tasks SET Name = ?, Description = ?, ProjectID = ?, TaskCompleted = ?, DueDate = ?, CompletionDate = ?, LastUpdatedDate = ?, Priority = ?, ParentTaskId = ? WHERE ID = ?`, + `UPDATE Tasks SET Name = ?, Description = ?, ProjectID = ?, TaskCompleted = ?, DueDate = ?, CompletionDate = ?, LastUpdatedDate = ?, Priority = ? WHERE ID = ?`, task.Name, task.Description, task.ProjectID, @@ -167,7 +130,6 @@ func (r *Repository) UpdateTask(task *models.Task) error { task.CompletionDate, task.LastUpdatedDate, task.Priority, - task.ParentTaskId, task.ID, ) return err