From eaca6e63bdf03b2f4c42ea25205e9b940e7beb81 Mon Sep 17 00:00:00 2001 From: Matt McCoy Date: Wed, 21 Feb 2024 14:44:22 -0500 Subject: [PATCH] refactor: fix tests and general clean up fix failing tests on CI & general clean up so all files follow a similar format --- backend/docs/docs.go | 144 ++++++++++++++++++------ backend/docs/swagger.json | 144 ++++++++++++++++++------ backend/docs/swagger.yaml | 97 +++++++++++----- backend/schema/tasks/routes.go | 84 +++++++++++--- backend/schema/tasks/task_test.go | 162 +++++++++------------------ backend/schema/tasks/transactions.go | 16 +-- 6 files changed, 415 insertions(+), 232 deletions(-) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 3087cf7..f958fba 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -446,7 +446,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Task" + "$ref": "#/definitions/tasks.TaskBody" } } ], @@ -561,6 +561,69 @@ const docTemplate = `{ } }, "/tasks/{tid}": { + "get": { + "description": "get a task given its id", + "tags": [ + "tasks" + ], + "summary": "get task by id", + "parameters": [ + { + "type": "integer", + "description": "the id of the task", + "name": "tid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Task" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "description": "Update the task_info field of a task by ID", + "tags": [ + "tasks" + ], + "summary": "Update Task Info", + "parameters": [ + { + "type": "integer", + "description": "Task ID", + "name": "tid", + "in": "path", + "required": true + }, + { + "description": "Update Task Info Request", + "name": "request_body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/tasks.TaskBody" + } + } + ], + "responses": { + "200": { + "description": "Updated Task", + "schema": { + "$ref": "#/definitions/models.Task" + } + } + } + }, "delete": { "description": "Delete a task by ID", "tags": [ @@ -627,7 +690,7 @@ const docTemplate = `{ } } }, - "/tasks/{tid}/assigned-users": { + "/tasks/{tid}/assigned": { "get": { "description": "Get list of users assigned to a task by task ID", "tags": [ @@ -662,41 +725,6 @@ const docTemplate = `{ } } }, - "/tasks/{tid}/info": { - "put": { - "description": "Update the task_info field of a task by ID", - "tags": [ - "tasks" - ], - "summary": "Update Task Info", - "parameters": [ - { - "type": "integer", - "description": "Task ID", - "name": "tid", - "in": "path", - "required": true - }, - { - "description": "Update Task Info Request", - "name": "request_body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/models.Task" - } - } - ], - "responses": { - "200": { - "description": "Updated Task", - "schema": { - "$ref": "#/definitions/models.Task" - } - } - } - } - }, "/tasks/{tid}/labels": { "get": { "description": "get a tasks labels given the task id", @@ -1075,6 +1103,48 @@ const docTemplate = `{ } } } + }, + "tasks.TaskBody": { + "type": "object", + "properties": { + "created_by": { + "description": "User ID", + "type": "string" + }, + "created_date": { + "type": "string" + }, + "end_date": { + "type": "string" + }, + "group_id": { + "type": "integer" + }, + "notes": { + "type": "string" + }, + "repeating": { + "type": "boolean" + }, + "repeating_end_date": { + "type": "string" + }, + "repeating_interval": { + "type": "string" + }, + "start_date": { + "type": "string" + }, + "task_info": { + "type": "string" + }, + "task_status": { + "type": "string" + }, + "task_type": { + "type": "string" + } + } } } }` diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index f60e7af..05ec608 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -439,7 +439,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/models.Task" + "$ref": "#/definitions/tasks.TaskBody" } } ], @@ -554,6 +554,69 @@ } }, "/tasks/{tid}": { + "get": { + "description": "get a task given its id", + "tags": [ + "tasks" + ], + "summary": "get task by id", + "parameters": [ + { + "type": "integer", + "description": "the id of the task", + "name": "tid", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Task" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "description": "Update the task_info field of a task by ID", + "tags": [ + "tasks" + ], + "summary": "Update Task Info", + "parameters": [ + { + "type": "integer", + "description": "Task ID", + "name": "tid", + "in": "path", + "required": true + }, + { + "description": "Update Task Info Request", + "name": "request_body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/tasks.TaskBody" + } + } + ], + "responses": { + "200": { + "description": "Updated Task", + "schema": { + "$ref": "#/definitions/models.Task" + } + } + } + }, "delete": { "description": "Delete a task by ID", "tags": [ @@ -620,7 +683,7 @@ } } }, - "/tasks/{tid}/assigned-users": { + "/tasks/{tid}/assigned": { "get": { "description": "Get list of users assigned to a task by task ID", "tags": [ @@ -655,41 +718,6 @@ } } }, - "/tasks/{tid}/info": { - "put": { - "description": "Update the task_info field of a task by ID", - "tags": [ - "tasks" - ], - "summary": "Update Task Info", - "parameters": [ - { - "type": "integer", - "description": "Task ID", - "name": "tid", - "in": "path", - "required": true - }, - { - "description": "Update Task Info Request", - "name": "request_body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/models.Task" - } - } - ], - "responses": { - "200": { - "description": "Updated Task", - "schema": { - "$ref": "#/definitions/models.Task" - } - } - } - } - }, "/tasks/{tid}/labels": { "get": { "description": "get a tasks labels given the task id", @@ -1068,6 +1096,48 @@ } } } + }, + "tasks.TaskBody": { + "type": "object", + "properties": { + "created_by": { + "description": "User ID", + "type": "string" + }, + "created_date": { + "type": "string" + }, + "end_date": { + "type": "string" + }, + "group_id": { + "type": "integer" + }, + "notes": { + "type": "string" + }, + "repeating": { + "type": "boolean" + }, + "repeating_end_date": { + "type": "string" + }, + "repeating_interval": { + "type": "string" + }, + "start_date": { + "type": "string" + }, + "task_info": { + "type": "string" + }, + "task_status": { + "type": "string" + }, + "task_type": { + "type": "string" + } + } } } } \ No newline at end of file diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 9232aec..f6b619e 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -144,6 +144,34 @@ definitions: type: string type: array type: object + tasks.TaskBody: + properties: + created_by: + description: User ID + type: string + created_date: + type: string + end_date: + type: string + group_id: + type: integer + notes: + type: string + repeating: + type: boolean + repeating_end_date: + type: string + repeating_interval: + type: string + start_date: + type: string + task_info: + type: string + task_status: + type: string + task_type: + type: string + type: object info: contact: {} description: This is an API for the Care-Wallet App. @@ -435,7 +463,7 @@ paths: name: request_body required: true schema: - $ref: '#/definitions/models.Task' + $ref: '#/definitions/tasks.TaskBody' responses: "201": description: Created Task @@ -459,6 +487,48 @@ paths: summary: Delete a Task tags: - tasks + get: + description: get a task given its id + parameters: + - description: the id of the task + in: path + name: tid + required: true + type: integer + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Task' + "400": + description: Bad Request + schema: + type: string + summary: get task by id + tags: + - tasks + put: + description: Update the task_info field of a task by ID + parameters: + - description: Task ID + in: path + name: tid + required: true + type: integer + - description: Update Task Info Request + in: body + name: request_body + required: true + schema: + $ref: '#/definitions/tasks.TaskBody' + responses: + "200": + description: Updated Task + schema: + $ref: '#/definitions/models.Task' + summary: Update Task Info + tags: + - tasks /tasks/{tid}/assign: post: description: assign users to task @@ -488,7 +558,7 @@ paths: summary: Assign Users To Task tags: - tasks - /tasks/{tid}/assigned-users: + /tasks/{tid}/assigned: get: description: Get list of users assigned to a task by task ID parameters: @@ -511,29 +581,6 @@ paths: summary: Get list of users assigned to a task tags: - tasks - /tasks/{tid}/info: - put: - description: Update the task_info field of a task by ID - parameters: - - description: Task ID - in: path - name: tid - required: true - type: integer - - description: Update Task Info Request - in: body - name: request_body - required: true - schema: - $ref: '#/definitions/models.Task' - responses: - "200": - description: Updated Task - schema: - $ref: '#/definitions/models.Task' - summary: Update Task Info - tags: - - tasks /tasks/{tid}/labels: delete: description: remove a label from a task given the task id, group id, and label diff --git a/backend/schema/tasks/routes.go b/backend/schema/tasks/routes.go index 47df0b5..9452a46 100644 --- a/backend/schema/tasks/routes.go +++ b/backend/schema/tasks/routes.go @@ -7,6 +7,7 @@ import ( "net/http" "strconv" "strings" + "time" "github.com/gin-gonic/gin" "github.com/jackc/pgx" @@ -17,20 +18,50 @@ type PgModel struct { } func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { - tasks := v1.Group("tasks") + tasks := v1.Group("") { tasks.GET("/filtered", c.GetFilteredTasks) - tasks.POST("/:tid/assign", c.AssignUsersToTask) - tasks.DELETE("/:tid/remove", c.RemoveUsersFromTask) tasks.GET("/assigned", c.GetTasksByAssignedUsers) tasks.POST("", c.CreateTask) - tasks.DELETE("/:tid", c.DeleteTask) - tasks.PUT("/:tid/info", c.UpdateTaskInfo) - tasks.GET("/:tid/assigned-users", c.GetUsersAssignedToTask) + + byId := tasks.Group("/:tid") + { + byId.GET("", c.GetTaskByID) + byId.DELETE("", c.DeleteTask) + byId.PUT("", c.UpdateTaskInfo) + byId.GET("/assigned", c.GetUsersAssignedToTask) + byId.POST("/assign", c.AssignUsersToTask) + byId.DELETE("/remove", c.RemoveUsersFromTask) + } } return tasks } +// GetTaskByID godoc +// +// @summary get task by id +// @description get a task given its id +// @tags tasks +// +// @param tid path int true "the id of the task" +// +// @success 200 {object} models.Task +// @failure 400 {object} string +// @router /tasks/{tid} [GET] +func (pg *PgModel) GetTaskByID(c *gin.Context) { + taskID, err := strconv.Atoi(c.Param("tid")) + if err != nil { + c.JSON(http.StatusBadRequest, err.Error()) + return + } + task, err := GetTaskByID(pg.Conn, taskID) + if err != nil { + c.JSON(http.StatusBadRequest, err.Error()) + return + } + c.JSON(http.StatusOK, task) +} + type TaskQuery struct { TaskID string `form:"taskID"` GroupID string `form:"groupID"` @@ -155,12 +186,29 @@ func (pg *PgModel) GetTasksByAssignedUsers(c *gin.Context) { c.JSON(http.StatusOK, tasks) } +type TaskBody struct { + GroupID int `json:"group_id"` + CreatedBy string `json:"created_by"` // User ID + CreatedDate time.Time `json:"created_date"` + StartDate *time.Time `json:"start_date"` + EndDate *time.Time `json:"end_date"` + Notes *string `json:"notes"` + Repeating bool `json:"repeating"` + RepeatingInterval *string `json:"repeating_interval"` + RepeatingEndDate *time.Time `json:"repeating_end_date"` + TaskStatus string `json:"task_status"` + TaskType string `json:"task_type"` + TaskInfo *string `json:"task_info"` +} + // CreateTask godoc // // @summary Create a New Task // @description Create a new task // @tags tasks -// @param request_body body models.Task true "Create Task Request" +// +// @param request_body body TaskBody true "Create Task Request" +// // @success 201 {object} models.Task "Created Task" // @router /tasks [post] func (pg *PgModel) CreateTask(c *gin.Context) { @@ -173,7 +221,7 @@ func (pg *PgModel) CreateTask(c *gin.Context) { } // Create the new task in the database - newTaskID, err := pg.CreateTaskInDB(requestBody) + newTaskID, err := CreateTaskInDB(pg.Conn, requestBody) if err != nil { fmt.Println("error creating task in the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -181,7 +229,7 @@ func (pg *PgModel) CreateTask(c *gin.Context) { } // Fetch the created task from the database - createdTask, err := pg.GetTaskByID(newTaskID) + createdTask, err := GetTaskByID(pg.Conn, newTaskID) if err != nil { fmt.Println("error fetching created task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -208,13 +256,13 @@ func (pg *PgModel) DeleteTask(c *gin.Context) { } // Check if the task exists before attempting to delete - if _, err := pg.GetTaskByID(taskID); err != nil { + if _, err := GetTaskByID(pg.Conn, taskID); err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } // Delete the task from the database - if err := pg.DeleteTaskInDB(taskID); err != nil { + if err := DeleteTaskInDB(pg.Conn, taskID); err != nil { fmt.Println("error deleting task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) return @@ -229,9 +277,9 @@ func (pg *PgModel) DeleteTask(c *gin.Context) { // @description Update the task_info field of a task by ID // @tags tasks // @param tid path int true "Task ID" -// @param request_body body models.Task true "Update Task Info Request" +// @param request_body body TaskBody true "Update Task Info Request" // @success 200 {object} models.Task "Updated Task" -// @router /tasks/{tid}/info [put] +// @router /tasks/{tid} [put] func (pg *PgModel) UpdateTaskInfo(c *gin.Context) { // Extract task ID from the path parameter taskID, err := strconv.Atoi(c.Param("tid")) @@ -258,14 +306,14 @@ func (pg *PgModel) UpdateTaskInfo(c *gin.Context) { } // Update the task_info field in the database - if err := pg.UpdateTaskInfoInDB(taskID, taskInfoRaw); err != nil { + if err := UpdateTaskInfoInDB(pg.Conn, taskID, taskInfoRaw); err != nil { fmt.Println("error updating task info in the database:", err) c.JSON(http.StatusBadRequest, err.Error()) return } // Fetch the updated task from the database - updatedTask, err := pg.GetTaskByID(taskID) + updatedTask, err := GetTaskByID(pg.Conn, taskID) if err != nil { fmt.Println("error fetching updated task from the database:", err) c.JSON(http.StatusBadRequest, err.Error()) @@ -288,20 +336,20 @@ type TaskUser struct { // @param tid path int true "Task ID" // @success 200 {array} string "List of user IDs assigned to the task" // @failure 400 {object} string -// @router /tasks/{tid}/assigned-users [get] +// @router /tasks/{tid}/assigned [get] func (pg *PgModel) GetUsersAssignedToTask(c *gin.Context) { // Extract task ID from the path parameter taskIDStr := c.Param("tid") taskID, err := strconv.Atoi(taskIDStr) if err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid task ID"}) + c.JSON(http.StatusBadRequest, err.Error()) return } // Get list of users assigned to the task userIDs, err := GetUsersAssignedToTaskFromDB(pg.Conn, taskID) if err != nil { - c.JSON(http.StatusBadRequest, gin.H{"error": "Failed to fetch users assigned to the task"}) + c.JSON(http.StatusBadRequest, err.Error()) return } diff --git a/backend/schema/tasks/task_test.go b/backend/schema/tasks/task_test.go index 87c5cb9..12847d8 100644 --- a/backend/schema/tasks/task_test.go +++ b/backend/schema/tasks/task_test.go @@ -244,22 +244,31 @@ func TestTaskGroup(t *testing.T) { }) t.Run("TestCreateTask_Success", func(t *testing.T) { - // Prepare a new task request body - taskData := map[string]interface{}{ - "group_id": 1, - "created_by": "user1", - "start_date": time.Now().Format(time.RFC3339), - "end_date": time.Now().Add(time.Hour).Format(time.RFC3339), - "notes": "Test task", - "repeating": false, - "repeating_interval": "", - "repeating_end_date": time.Now().Add(2 * time.Hour).Format(time.RFC3339), - "task_status": "INCOMPLETE", - "task_type": "other", - "task_info": map[string]interface{}{ - "details": "Test details", - }, + // Creating a Task instance + startDate := time.Now().UTC() + endDate := time.Now().Add(24 * time.Hour).UTC() + notes := "This is a sample task" + repeating := true + repeatingInterval := "Weekly" + repeatingEndDate := time.Now().Add(7 * 24 * time.Hour).UTC() + taskInfo := `{"info": "Additional information about the task"}` + + taskData := models.Task{ + TaskID: 1, + GroupID: 1, + CreatedBy: "user1", + CreatedDate: time.Now().UTC(), + StartDate: &startDate, + EndDate: &endDate, + Notes: ¬es, + Repeating: repeating, + RepeatingInterval: &repeatingInterval, + RepeatingEndDate: &repeatingEndDate, + TaskStatus: "INCOMPLETE", + TaskType: "med_mgmt", + TaskInfo: &taskInfo, } + taskJSON, err := json.Marshal(taskData) if err != nil { t.Error("Failed to marshal task data to JSON:", err) @@ -283,17 +292,17 @@ func TestTaskGroup(t *testing.T) { } // Validate the response body - var createdTask map[string]interface{} + var createdTask models.Task err = json.Unmarshal(w.Body.Bytes(), &createdTask) if err != nil { t.Error("Failed to unmarshal JSON:", err) } // Add more specific assertions based on the expected response - if createdTask["task_id"] == nil { + if createdTask.TaskID == -1 { t.Error("Expected task ID to be present") } - if createdTask["created_by"] != "user1" { + if createdTask.CreatedBy != "user1" { t.Error("Unexpected created_by value") } // Add more assertions as needed @@ -360,99 +369,38 @@ func TestTaskGroup(t *testing.T) { }) t.Run("TestUpdateTaskInfo", func(t *testing.T) { - // Mock the successful update of task info in the database - var updateTaskInfoInDBFunc func(taskID int, taskInfoRaw json.RawMessage) error - - // Mock the successful retrieval of the task by ID - var getTaskByIDFunc func(taskID int) (models.Task, error) - - // Create a new Gin router - router := gin.Default() - - // Attach the UpdateTaskInfo route to the router - router.PUT("/tasks/:tid/info", func(c *gin.Context) { - // Extract task ID from the path parameter - taskIDStr := c.Param("tid") - taskID, err := strconv.Atoi(taskIDStr) - if err != nil { - c.JSON(http.StatusBadRequest, err.Error()) - return - } - - // Bind the request body to the UpdateTaskInfoRequest struct - var requestBody struct { - GroupID int `json:"group_id"` - CreatedBy string `json:"created_by"` - StartDate time.Time `json:"start_date"` - EndDate time.Time `json:"end_date"` - Notes string `json:"notes"` - Repeating bool `json:"repeating"` - RepeatingInterval string `json:"repeating_interval"` - RepeatingEndDate time.Time `json:"repeating_end_date"` - TaskStatus string `json:"task_status"` - TaskType string `json:"task_type"` - TaskInfo map[string]interface{} `json:"task_info"` - } - if err := c.BindJSON(&requestBody); err != nil { - c.JSON(http.StatusBadRequest, err.Error()) - return - } - - // Convert TaskInfo to json.RawMessage - taskInfoRaw, err := json.Marshal(requestBody.TaskInfo) - if err != nil { - c.JSON(http.StatusBadRequest, err.Error()) - return - } - - // Mock the successful update of task info in the database - if updateTaskInfoInDBFunc != nil { - if err := updateTaskInfoInDBFunc(taskID, taskInfoRaw); err != nil { - c.JSON(http.StatusBadRequest, err.Error()) - return - } - } - - // Mock the successful retrieval of the task by ID - if getTaskByIDFunc != nil { - task, err := getTaskByIDFunc(taskID) - if err != nil { - c.JSON(http.StatusBadRequest, err.Error()) - return - } - - // Fetch the updated task from the database - c.JSON(http.StatusOK, task) - return - } - - c.Status(http.StatusOK) - }) - - // Prepare a request body with task data - requestBody := map[string]interface{}{ - "group_id": 1, - "created_by": "user1", - "start_date": time.Now().Format(time.RFC3339), - "end_date": time.Now().Add(time.Hour).Format(time.RFC3339), - "notes": "Test task", - "repeating": false, - "repeating_interval": "", - "repeating_end_date": time.Now().Add(2 * time.Hour).Format(time.RFC3339), - "task_status": "INCOMPLETE", - "task_type": "other", - "task_info": map[string]interface{}{ - "details": "Test details", - }, - } - requestBodyJSON, err := json.Marshal(requestBody) + // Creating a Task instance + startDate := time.Now().UTC() + endDate := time.Now().Add(24 * time.Hour).UTC() + notes := "This is a sample task" + repeating := true + repeatingInterval := "Weekly" + repeatingEndDate := time.Now().Add(7 * 24 * time.Hour).UTC() + taskInfo := `{"info": "Additional information about the task"}` + + taskData := models.Task{ + TaskID: 1, + GroupID: 1, + CreatedBy: "user1", + CreatedDate: time.Now().UTC(), + StartDate: &startDate, + EndDate: &endDate, + Notes: ¬es, + Repeating: repeating, + RepeatingInterval: &repeatingInterval, + RepeatingEndDate: &repeatingEndDate, + TaskStatus: "INCOMPLETE", + TaskType: "med_mgmt", + TaskInfo: &taskInfo, + } + requestBodyJSON, err := json.Marshal(taskData) if err != nil { t.Fatal("Failed to marshal task data to JSON:", err) return } // Perform a PUT request to the /tasks/:tid/info endpoint - req, err := http.NewRequest("PUT", "/tasks/1/info", bytes.NewBuffer(requestBodyJSON)) + req, err := http.NewRequest("PUT", "/tasks/1", bytes.NewBuffer(requestBodyJSON)) if err != nil { t.Fatal("Failed to create HTTP request:", err) return @@ -474,7 +422,7 @@ func TestTaskGroup(t *testing.T) { t.Run("TestGetUsersAssignedToTask", func(t *testing.T) { // Create a new recorder and request w := httptest.NewRecorder() - req, _ := http.NewRequest("GET", "/tasks/1/assigned-users", nil) + req, _ := http.NewRequest("GET", "/tasks/2/assigned", nil) // Serve the request using the router router.ServeHTTP(w, req) @@ -493,7 +441,7 @@ func TestTaskGroup(t *testing.T) { t.Error("Failed to unmarshal JSON") } - expectedUsers := []string{"user1"} + expectedUsers := []string{"user3", "user4"} if !reflect.DeepEqual(expectedUsers, responseUsers) { t.Error("Result was not correct") } diff --git a/backend/schema/tasks/transactions.go b/backend/schema/tasks/transactions.go index 19e06e2..31895b5 100644 --- a/backend/schema/tasks/transactions.go +++ b/backend/schema/tasks/transactions.go @@ -157,12 +157,12 @@ func GetTasksByAssignedFromDB(pool *pgx.Conn, userIDs []string) ([]models.Task, } // CreateTaskInDB creates a new task in the database and returns its ID -func (pg *PgModel) CreateTaskInDB(newTask models.Task) (int, error) { +func CreateTaskInDB(pool *pgx.Conn, newTask models.Task) (int, error) { query := ` INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING task_id` var newTaskID int - err := pg.Conn.QueryRow( + err := pool.QueryRow( query, newTask.GroupID, newTask.CreatedBy, @@ -182,30 +182,30 @@ func (pg *PgModel) CreateTaskInDB(newTask models.Task) (int, error) { } // DeleteTaskInDB deletes a task from the database by ID -func (pg *PgModel) DeleteTaskInDB(taskID int) error { +func DeleteTaskInDB(pool *pgx.Conn, taskID int) error { // Assuming "task" table structure, adjust the query based on your schema query := "DELETE FROM task WHERE task_id = $1" - _, err := pg.Conn.Exec(query, taskID) + _, err := pool.Exec(query, taskID) return err } // UpdateTaskInfoInDB updates the task_info field in the database -func (pg *PgModel) UpdateTaskInfoInDB(taskID int, taskInfo json.RawMessage) error { +func UpdateTaskInfoInDB(pool *pgx.Conn, taskID int, taskInfo json.RawMessage) error { // Assuming "task" table structure, adjust the query based on your schema query := "UPDATE task SET task_info = $1 WHERE task_id = $2" - _, err := pg.Conn.Exec(query, taskInfo, taskID) + _, err := pool.Exec(query, taskInfo, taskID) return err } // GetTaskByID fetches a task from the database by its ID -func (pg *PgModel) GetTaskByID(taskID int) (models.Task, error) { +func GetTaskByID(pool *pgx.Conn, taskID int) (models.Task, error) { query := ` SELECT task_id, group_id, created_by, created_date, start_date, end_date, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info FROM task WHERE task_id = $1` var task models.Task - err := pg.Conn.QueryRow(query, taskID).Scan( + err := pool.QueryRow(query, taskID).Scan( &task.TaskID, &task.GroupID, &task.CreatedBy,