From e879faee0f77bc997ea548aa60da2850a72b6182 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sun, 13 Oct 2024 16:46:01 +0000 Subject: [PATCH] feat(task): api --- api/tasks/tasks.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/api/tasks/tasks.go b/api/tasks/tasks.go index 7b3201c9..50f65348 100644 --- a/api/tasks/tasks.go +++ b/api/tasks/tasks.go @@ -11,7 +11,7 @@ import ( func TaskMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - taskID, err := helpers.GetStrParam("task_id", w, r) + taskID, err := helpers.GetIntParam("task_id", w, r) if err != nil { helpers.WriteErrorStatus(w, err.Error(), http.StatusBadRequest) } @@ -61,18 +61,22 @@ func GetTasks(w http.ResponseWriter, r *http.Request) { func DeleteTask(w http.ResponseWriter, r *http.Request) { - taskID := context.Get(r, "task_id").(string) + taskID := context.Get(r, "task_id").(int) pool := context.Get(r, "task_pool").(*task2.TaskPool) - var task db.Task + var task *db.Task for _, t := range pool.Queue { if t.Task.ID == taskID { - task = t.Task + task = &t.Task break } } - pool.StopTask(task, false) + if task != nil { + pool.StopTask(*task, false) + } + + helpers.WriteJSON(w, http.StatusNoContent, nil) }