Implement client side enable, disable, edit

This commit is contained in:
bel
2020-03-15 20:14:03 +00:00
parent b7bfee96a3
commit 19d4b645b8
8 changed files with 63 additions and 18 deletions

View File

@@ -33,6 +33,7 @@ func (s *Server) list(w http.ResponseWriter, r *http.Request) {
if err != nil {
panic(err)
}
out[i]["disabled"] = j.Disabled
out[i]["id"] = j.Name
out[i]["title"] = j.Title
out[i]["cron"] = j.Schedule

View File

@@ -13,11 +13,11 @@ func (s *Server) Routes() error {
handler http.HandlerFunc
}{
{
path: fmt.Sprintf("/upserts"),
handler: s.gzip(s.authenticate(s.upserts)),
path: fmt.Sprintf("/api/job/upsert"),
handler: s.gzip(s.authenticate(s.upsert)),
},
{
path: fmt.Sprintf("/list"),
path: fmt.Sprintf("/api/job/list"),
handler: s.gzip(s.authenticate(s.list)),
},
{

View File

@@ -19,6 +19,7 @@ type upsertRequest struct {
Language string `json:"language"`
Cron string `json:"cron"`
Script string `json:"script"`
Disabled bool `json:"disabled"`
}
func newUpsertRequest(r io.Reader) (upsertRequest, error) {
@@ -51,7 +52,7 @@ func (u *upsertRequest) validate() error {
return nil
}
func (s *Server) upserts(w http.ResponseWriter, r *http.Request) {
func (s *Server) upsert(w http.ResponseWriter, r *http.Request) {
upsert, err := newUpsertRequest(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)