/
handler_job_delete.go
44 lines (37 loc) · 1.04 KB
/
handler_job_delete.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
41
42
43
44
package job
import (
"net/http"
"strconv"
"github.com/kenza-ai/kenza/api/httputil"
)
// Delete jobs
func Delete(jobs Store) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accountID, err := strconv.ParseInt(httputil.Param(r, "accountID"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
projectID, err := strconv.ParseInt(httputil.Param(r, "projectID"), 10, 64)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
jobsToDeleteStr, _ := r.URL.Query()["id"]
jobIDsToDelete := []int64{}
for _, job := range jobsToDeleteStr {
jobID, err := strconv.ParseInt(job, 10, 64)
if err != nil {
e("error parsing job id query param into integer: %s", err.Error())
continue
}
jobIDsToDelete = append(jobIDsToDelete, jobID)
}
err = jobs.DeleteJobs(accountID, projectID, jobIDsToDelete)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
})
}