优化后台文章页的标签表现
This commit is contained in:
@@ -294,12 +294,16 @@ func UpdatePost(c *gin.Context) {
|
||||
updates["is_top"] = req.IsTop
|
||||
}
|
||||
|
||||
// 处理标签
|
||||
if len(req.Tags) > 0 {
|
||||
tags := findOrCreateTags(req.Tags)
|
||||
if err := database.DB.Model(&post).Association("Tags").Replace(tags); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "更新文章标签失败"})
|
||||
return
|
||||
// 处理标签(nil 表示本次请求不涉及标签;空数组表示移除全部标签)
|
||||
if req.Tags != nil {
|
||||
if len(req.Tags) > 0 {
|
||||
tags := findOrCreateTags(req.Tags)
|
||||
if err := database.DB.Model(&post).Association("Tags").Replace(tags); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "更新文章标签失败"})
|
||||
return
|
||||
}
|
||||
} else {
|
||||
database.DB.Model(&post).Association("Tags").Clear()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user