feat(channel): 支持安全删除渠道并保留历史数据
This commit is contained in:
@@ -152,6 +152,22 @@ func (h *ChannelHandler) Update(c *gin.Context) {
|
||||
middleware.JSON(c, toChannelView(channel))
|
||||
}
|
||||
|
||||
func (h *ChannelHandler) Delete(c *gin.Context) {
|
||||
if !requireTenantAdmin(c) {
|
||||
return
|
||||
}
|
||||
var channel model.Channel
|
||||
if err := model.DB.Where("id = ? AND tenant_id = ?", c.Param("id"), middleware.GetTenantID(c)).First(&channel).Error; err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"code": 404, "message": "渠道不存在"})
|
||||
return
|
||||
}
|
||||
if err := model.DB.Delete(&channel).Error; err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"code": 500, "message": "删除失败"})
|
||||
return
|
||||
}
|
||||
middleware.JSON(c, gin.H{"id": channel.ID, "deleted": true})
|
||||
}
|
||||
|
||||
type createChannelReq struct {
|
||||
Type string `json:"type" binding:"required"`
|
||||
Name string `json:"name"`
|
||||
|
||||
Reference in New Issue
Block a user