Merge branch 'master' into master

This commit is contained in:
玖亖伍
2022-05-09 18:19:08 +08:00
committed by GitHub
17 changed files with 366 additions and 88 deletions

View File

@@ -518,7 +518,6 @@ func (c *BookController) Create() {
book.Identify = identify
book.DocCount = 0
book.MemberId = c.Member.MemberId
book.CommentCount = 0
book.Version = time.Now().Unix()
book.IsEnableShare = 0
book.IsUseFirstDocument = 1
@@ -636,7 +635,6 @@ func (c *BookController) Import() {
book.Identify = identify
book.DocCount = 0
book.MemberId = c.Member.MemberId
book.CommentCount = 0
book.Version = time.Now().Unix()
book.ItemId = itemId

View File

@@ -0,0 +1,97 @@
package controllers
import (
"strings"
"time"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/models"
"github.com/mindoc-org/mindoc/utils/pagination"
)
type CommentController struct {
BaseController
}
func (c *CommentController) Lists() {
docid, _ := c.GetInt("docid", 0)
pageIndex, _ := c.GetInt("page", 1)
// 获取评论、分页
comments, count, pageIndex := models.NewComment().QueryCommentByDocumentId(docid, pageIndex, conf.PageSize, c.Member)
page := pagination.PageUtil(int(count), pageIndex, conf.PageSize, comments)
var data struct {
DocId int `json:"doc_id"`
Page pagination.Page `json:"page"`
}
data.DocId = docid
data.Page = page
c.JsonResult(0, "ok", data)
return
}
func (c *CommentController) Create() {
content := c.GetString("content")
id, _ := c.GetInt("doc_id")
_, err := models.NewDocument().Find(id)
if err != nil {
c.JsonResult(1, "文章不存在")
}
m := models.NewComment()
m.DocumentId = id
if len(c.Member.RealName) != 0 {
m.Author = c.Member.RealName
} else {
m.Author = c.Member.Account
}
m.MemberId = c.Member.MemberId
m.IPAddress = c.Ctx.Request.RemoteAddr
m.IPAddress = strings.Split(m.IPAddress, ":")[0]
m.CommentDate = time.Now()
m.Content = content
m.Insert()
var data struct {
DocId int `json:"doc_id"`
}
data.DocId = id
c.JsonResult(0, "ok", data)
}
func (c *CommentController) Index() {
c.Prepare()
c.TplName = "comment/index.tpl"
}
func (c *CommentController) Delete() {
if c.Ctx.Input.IsPost() {
id, _ := c.GetInt("id", 0)
m, err := models.NewComment().Find(id)
if err != nil {
c.JsonResult(1, "评论不存在")
}
doc, err := models.NewDocument().Find(m.DocumentId)
if err != nil {
c.JsonResult(1, "文章不存在")
}
// 判断是否有权限删除
bookRole, _ := models.NewRelationship().FindForRoleId(doc.BookId, c.Member.MemberId)
if m.CanDelete(c.Member.MemberId, bookRole) {
err := m.Delete()
if err != nil {
c.JsonResult(1, "删除错误")
} else {
c.JsonResult(0, "ok")
}
} else {
c.JsonResult(1, "没有权限删除")
}
}
}

View File

@@ -1,19 +0,0 @@
package controllers
type CommentController struct {
BaseController
}
func (c *CommentController) Lists() {
}
func (c *CommentController) Create() {
c.JsonResult(0, "ok")
}
func (c *CommentController) Index() {
c.Prepare()
c.TplName = "comment/index.tpl"
}