forked from thecodeteam/libstorage
/
task_routes.go
40 lines (33 loc) · 869 Bytes
/
task_routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package tasks
import (
"fmt"
"net/http"
"github.com/codedellemc/libstorage/api/server/httputils"
"github.com/codedellemc/libstorage/api/server/services"
"github.com/codedellemc/libstorage/api/types"
"github.com/codedellemc/libstorage/api/utils"
)
func (r *router) tasks(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
tasks := map[string]*types.Task{}
for t := range services.Tasks(ctx) {
tasks[fmt.Sprintf("%d", t.ID)] = t
}
httputils.WriteJSON(w, http.StatusOK, tasks)
return nil
}
func (r *router) taskInspect(
ctx types.Context,
w http.ResponseWriter,
req *http.Request,
store types.Store) error {
task := services.TaskInspect(ctx, store.GetInt("taskID"))
if task == nil {
return utils.NewNotFoundError(store.GetString("taskID"))
}
httputils.WriteJSON(w, http.StatusOK, task)
return nil
}