From 26fa3267a0924581a5be82acafdd9bd2484aa789 Mon Sep 17 00:00:00 2001 From: Eric Cornely Date: Thu, 18 May 2017 14:29:57 +0200 Subject: [PATCH] Get tasks details Reference issue #356 Get a single task --- api-docs.yml | 13 +++++++++++++ api/router.go | 1 + api/tasks/http.go | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/api-docs.yml b/api-docs.yml index ade480a7..9cc321d8 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -923,6 +923,19 @@ paths: description: Task queued schema: $ref: "#/definitions/Task" + /project/{project_id}/tasks/{task_id}: + parameters: + - $ref: "#/parameters/project_id" + - $ref: "#/parameters/task_id" + get: + tags: + - project + summary: Get a single task + responses: + 200: + description: Task + schema: + $ref: "#/definitions/Task" /project/{project_id}/tasks/{task_id}/output: parameters: - $ref: '#/parameters/project_id' diff --git a/api/router.go b/api/router.go index 82ba4290..a243cb10 100644 --- a/api/router.go +++ b/api/router.go @@ -99,6 +99,7 @@ func Route() mulekick.Router { api.Get("/tasks", tasks.GetAll) api.Post("/tasks", tasks.AddTask) api.Get("/tasks/{task_id}/output", tasks.GetTaskMiddleware, tasks.GetTaskOutput) + api.Get("/tasks/{task_id}", tasks.GetTaskMiddleware, tasks.GetTask) api.Delete("/tasks/{task_id}", tasks.GetTaskMiddleware, tasks.RemoveTask) }(api.Group("/project/{project_id}")) diff --git a/api/tasks/http.go b/api/tasks/http.go index 8071a76a..d066a35c 100644 --- a/api/tasks/http.go +++ b/api/tasks/http.go @@ -73,6 +73,11 @@ func GetAll(w http.ResponseWriter, r *http.Request) { mulekick.WriteJSON(w, http.StatusOK, tasks) } +func GetTask(w http.ResponseWriter, r *http.Request) { + task := context.Get(r, "task").(db.Task) + mulekick.WriteJSON(w, http.StatusOK, task) +} + func GetTaskMiddleware(w http.ResponseWriter, r *http.Request) { taskID, err := util.GetIntParam("task_id", w, r) if err != nil {