feat: 云账号编辑功能 + 通知渠道种子数据 + 修复mock.go编译错误
- 新增 PUT /cloud-accounts/:id 后端端点(UpdateCloudAccount handler + 路由注册) - 前端 CloudAccountManager 添加编辑弹窗:复用创建表单,凭证留空保持不变 - 修复 scripts/mock.go 编译错误:补充缺失的 generateNotifyChannels 函数(5种通知渠道种子) - 包含前序未提交的告警通知渠道 CRUD 后端API + AlertManager 通知配置前端UI
This commit is contained in:
1 parent
01a9bebb0c
commit
af2e60acd9
9 files changed
+822
-51
No files matched your search
@@ -469,6 +469,70 @@ func (h *CloudAccountHandler) CreateCloudAccount(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateCloudAccount 更新云账号
|
||||
// @Summary 更新云账号
|
||||
// @Description 更新指定云账号信息
|
||||
// @Tags 云账号
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Param id path int true "云账号ID"
|
||||
// @Param request body createCloudAccountRequest true "更新请求"
|
||||
// @Success 200 {object} models.Response{data=models.CloudAccount}
|
||||
// @Router /cloud-accounts/{id} [put]
|
||||
func (h *CloudAccountHandler) UpdateCloudAccount(c *gin.Context) {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
var req createCloudAccountRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, models.Response{
|
||||
Code: 400,
|
||||
Message: "请求参数错误: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var account models.CloudAccount
|
||||
if err := h.db.First(&account, id).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, models.Response{
|
||||
Code: 404,
|
||||
Message: "云账号不存在",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 只在提供非空值时更新凭证字段
|
||||
if strings.TrimSpace(req.Name) != "" {
|
||||
account.Name = strings.TrimSpace(req.Name)
|
||||
}
|
||||
if strings.TrimSpace(req.Provider) != "" {
|
||||
account.Provider = strings.TrimSpace(req.Provider)
|
||||
}
|
||||
if strings.TrimSpace(req.AccessKey) != "" {
|
||||
account.AccessKey = req.AccessKey
|
||||
}
|
||||
if strings.TrimSpace(req.SecretKey) != "" {
|
||||
account.SecretKey = req.SecretKey
|
||||
}
|
||||
if strings.TrimSpace(req.Status) != "" {
|
||||
account.Status = strings.TrimSpace(req.Status)
|
||||
}
|
||||
account.MonthlyCost = req.MonthlyCost
|
||||
|
||||
if err := h.db.Save(&account).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.Response{
|
||||
Code: 500,
|
||||
Message: "更新失败",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, models.Response{
|
||||
Code: 200,
|
||||
Message: "更新成功",
|
||||
Data: account,
|
||||
})
|
||||
}
|
||||
|
||||
// DeleteCloudAccount 删除云账号
|
||||
// @Summary 删除云账号
|
||||
// @Description 删除指定云账号
|
||||
|
||||
Reference in new issue
Block a user