mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
feat: Update notification trigger patterns and add alert trigger
This commit is contained in:
@@ -326,6 +326,11 @@ func InitRoutes(app *gin.Engine) (err error) {
|
||||
Path: "/:id",
|
||||
HandlerFunc: GetSetting,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/:id",
|
||||
HandlerFunc: PostSetting,
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/:id",
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/crawlab-team/crawlab/core/models/models"
|
||||
models2 "github.com/crawlab-team/crawlab/core/models/models/v2"
|
||||
"errors"
|
||||
"github.com/crawlab-team/crawlab/core/models/models/v2"
|
||||
"github.com/crawlab-team/crawlab/core/models/service"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
func GetSetting(c *gin.Context) {
|
||||
@@ -13,11 +14,45 @@ func GetSetting(c *gin.Context) {
|
||||
key := c.Param("id")
|
||||
|
||||
// setting
|
||||
s, err := service.NewModelServiceV2[models2.SettingV2]().GetOne(bson.M{"key": key}, nil)
|
||||
s, err := service.NewModelServiceV2[models.SettingV2]().GetOne(bson.M{"key": key}, nil)
|
||||
if err != nil {
|
||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||
HandleSuccess(c)
|
||||
return
|
||||
}
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
HandleSuccessWithData(c, s)
|
||||
}
|
||||
|
||||
func PostSetting(c *gin.Context) {
|
||||
// key
|
||||
key := c.Param("id")
|
||||
|
||||
// settings
|
||||
var s models.SettingV2
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if s.Key == "" {
|
||||
s.Key = key
|
||||
}
|
||||
|
||||
u := GetUserFromContextV2(c)
|
||||
|
||||
s.SetCreated(u.Id)
|
||||
s.SetUpdated(u.Id)
|
||||
|
||||
id, err := service.NewModelServiceV2[models.SettingV2]().InsertOne(s)
|
||||
if err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
s.Id = id
|
||||
|
||||
HandleSuccessWithData(c, s)
|
||||
}
|
||||
@@ -27,13 +62,13 @@ func PutSetting(c *gin.Context) {
|
||||
key := c.Param("id")
|
||||
|
||||
// settings
|
||||
var s models.Setting
|
||||
var s models.SettingV2
|
||||
if err := c.ShouldBindJSON(&s); err != nil {
|
||||
HandleErrorInternalServerError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
modelSvc := service.NewModelServiceV2[models2.SettingV2]()
|
||||
modelSvc := service.NewModelServiceV2[models.SettingV2]()
|
||||
|
||||
// setting
|
||||
_s, err := modelSvc.GetOne(bson.M{"key": key}, nil)
|
||||
|
||||
Reference in New Issue
Block a user