Add support for schedules (#137)
Reviewed-on: #137
This commit was merged in pull request #137.
This commit is contained in:
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gitea.seeseepuff.be/seeseemelk/mysqlite"
|
||||
"github.com/adhocore/gronx"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -436,6 +438,14 @@ func createTask(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if taskRequest.Schedule != nil {
|
||||
valid := gronx.IsValid(*taskRequest.Schedule)
|
||||
if !valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("Invalid cron schedule: %s", *taskRequest.Schedule)})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// If assigned is not nil, check if user exists
|
||||
if taskRequest.Assigned != nil {
|
||||
exists, err := db.UserExists(*taskRequest.Assigned)
|
||||
@@ -513,6 +523,11 @@ func putTask(c *gin.Context) {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Task not found"})
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
log.Printf("Error getting task: %v", err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": ErrInternalServerError})
|
||||
return
|
||||
}
|
||||
|
||||
err = db.UpdateTask(taskId, &taskRequest)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user