Skip to content

Commit

Permalink
fix: unable to update cron expression
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Apr 5, 2023
1 parent 193fcc3 commit 3fd8f8a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions controllers/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"github.com/crawlab-team/crawlab-core/config"
"github.com/crawlab-team/crawlab-core/errors"
"github.com/crawlab-team/crawlab-core/interfaces"
"github.com/crawlab-team/crawlab-core/models/delegate"
"github.com/crawlab-team/crawlab-core/models/models"
Expand Down Expand Up @@ -57,6 +58,39 @@ func (ctr *scheduleController) Post(c *gin.Context) {
HandleSuccessWithData(c, s)
}

func (ctr *scheduleController) Put(c *gin.Context) {
id := c.Param("id")
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
HandleErrorBadRequest(c, err)
return
}
var s models.Schedule
if err := c.ShouldBindJSON(&s); err != nil {
HandleErrorBadRequest(c, err)
return
}
if s.GetId() != oid {
HandleErrorBadRequest(c, errors.ErrorHttpBadRequest)
return
}
if err := delegate.NewModelDelegate(&s).Save(); err != nil {
HandleErrorInternalServerError(c, err)
return
}
if s.Enabled {
if err := ctr.ctx.scheduleSvc.Disable(&s, GetUserFromContext(c)); err != nil {
HandleErrorInternalServerError(c, err)
return
}
if err := ctr.ctx.scheduleSvc.Enable(&s, GetUserFromContext(c)); err != nil {
HandleErrorInternalServerError(c, err)
return
}
}
HandleSuccessWithData(c, s)
}

func (ctr *scheduleController) Delete(c *gin.Context) {
id := c.Param("id")
oid, err := primitive.ObjectIDFromHex(id)
Expand Down

0 comments on commit 3fd8f8a

Please sign in to comment.