Add support for schedules (#137)
All checks were successful
Backend Build and Test / build (push) Successful in 3m42s
Backend Deploy / build (push) Successful in 4m46s

Reviewed-on: #137
This commit was merged in pull request #137.
This commit is contained in:
2025-05-30 20:22:33 +02:00
parent 5a20e76df2
commit 06c8ebcbcc
11 changed files with 199 additions and 23 deletions

View File

@@ -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 {