feat: implement V2 alert center and scoped alert governance
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/go-kratos/kratos/v3/errors"
|
||||
"kra/internal/service/business"
|
||||
"kra/internal/service/dto"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -46,17 +47,31 @@ func (h *AlertRule) Find(c *gin.Context) {
|
||||
OKWithData(c, v)
|
||||
}
|
||||
func (h *AlertRule) Save(c *gin.Context) {
|
||||
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 16384)
|
||||
var req dto.AlertRuleRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, "预警规则参数不正确")
|
||||
return
|
||||
}
|
||||
var requestedID uint64
|
||||
if req.ID != "" {
|
||||
var err error
|
||||
requestedID, err = strconv.ParseUint(req.ID.String(), 10, 64)
|
||||
if err != nil {
|
||||
Fail(c, "规则 ID 不正确")
|
||||
return
|
||||
}
|
||||
}
|
||||
if (c.Request.Method == http.MethodPost && requestedID != 0) || (c.Request.Method == http.MethodPut && requestedID == 0) {
|
||||
Fail(c, "新建或编辑规则的 ID 不正确")
|
||||
return
|
||||
}
|
||||
id, err := h.service.Save(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, gin.H{"id": id})
|
||||
OKWithData(c, gin.H{"id": strconv.FormatUint(id, 10)})
|
||||
}
|
||||
func (h *AlertRule) Delete(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
|
||||
Reference in New Issue
Block a user