38 lines
680 B
Go
38 lines
680 B
Go
package controllers
|
|
|
|
import (
|
|
"liteblog/models"
|
|
"liteblog/syserrors"
|
|
"log"
|
|
)
|
|
|
|
type CommentController struct {
|
|
BaseController
|
|
}
|
|
|
|
// 新增评论
|
|
// @router /new/:key [post]
|
|
func (c *CommentController) NewComment() {
|
|
log.Print("开始评论了....")
|
|
|
|
c.MustLogin()
|
|
key := c.Ctx.Input.Param(":key")
|
|
content := c.GetMustString("content", "请输入评论内容")
|
|
k := c.UUID()
|
|
|
|
comment := &models.Comment{
|
|
Key: k,
|
|
NoteKey: key,
|
|
User: c.User,
|
|
UserId: int(c.User.ID),
|
|
Content: content,
|
|
}
|
|
|
|
if err := models.SaveComment(comment); err != nil {
|
|
log.Print("保存失败了")
|
|
|
|
c.Abort500(syserrors.NewError("保存失败", err))
|
|
}
|
|
|
|
c.JSONOkH("保存成功", nil)
|
|
} |