mirror of https://github.com/mindoc-org/mindoc.git
完善评论功能
parent
e6726562ce
commit
97165256c0
|
@ -7,3 +7,13 @@ type CommentController struct {
|
|||
func (c *CommentController) Lists() {
|
||||
|
||||
}
|
||||
|
||||
func (c *CommentController) Create() {
|
||||
|
||||
c.JsonResult(0,"ok")
|
||||
}
|
||||
|
||||
func (c *CommentController) Index() {
|
||||
c.Prepare()
|
||||
c.TplName = "comment/index.tpl"
|
||||
}
|
|
@ -366,7 +366,7 @@ func (c *ManagerController) DeleteComment() {
|
|||
|
||||
comment := models.NewComment()
|
||||
|
||||
if err := comment.Find(comment_id); err != nil {
|
||||
if _,err := comment.Find(comment_id); err != nil {
|
||||
c.JsonResult(6002,"评论不存在")
|
||||
}
|
||||
|
||||
|
|
2
main.go
2
main.go
|
@ -18,7 +18,7 @@ func main() {
|
|||
commands.RegisterFunction()
|
||||
|
||||
beego.SetStaticPath("uploads","uploads")
|
||||
|
||||
|
||||
fmt.Println(os.Args[0])
|
||||
|
||||
beego.Run()
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
//Comment struct
|
||||
type Comment struct {
|
||||
CommentId int `orm:"pk;auto;unique;column(comment_id)" json:"comment_id"`
|
||||
Floor int `orm:"column(floor);type(unsigned);default(0)" json:"floor"`
|
||||
BookId int `orm:"column(book_id);type(int)" json:"book_id"`
|
||||
// DocumentId 评论所属的文档.
|
||||
DocumentId int `orm:"column(document_id);type(int)" json:"document_id"`
|
||||
|
@ -49,12 +50,14 @@ func (m *Comment) TableNameWithPrefix() string {
|
|||
func NewComment() *Comment {
|
||||
return &Comment{}
|
||||
}
|
||||
func (m *Comment) Find(id int) error {
|
||||
func (m *Comment) Find(id int) (*Comment,error) {
|
||||
if id <= 0 {
|
||||
return ErrInvalidParameter
|
||||
return m,ErrInvalidParameter
|
||||
}
|
||||
o := orm.NewOrm()
|
||||
return o.Read(m)
|
||||
err := o.Read(m)
|
||||
|
||||
return m,err
|
||||
}
|
||||
|
||||
func (m *Comment) Update(cols... string) error {
|
||||
|
@ -158,10 +161,6 @@ func (m *Comment) Insert() error {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package models
|
||||
|
||||
import "github.com/astaxie/beego/orm"
|
||||
|
||||
type CommentResult struct {
|
||||
Comment
|
||||
Author string `json:"author"`
|
||||
ReplyAccount string `json:"reply_account"`
|
||||
}
|
||||
|
||||
func (m *CommentResult) FindForDocumentToPager(doc_id, page_index,page_size int) (comments []*CommentResult,totalCount int,err error) {
|
||||
|
||||
o := orm.NewOrm()
|
||||
|
||||
sql1 := `
|
||||
SELECT
|
||||
comment.* ,
|
||||
parent.* ,
|
||||
member.account AS author,
|
||||
p_member.account AS reply_account
|
||||
FROM md_comments AS comment
|
||||
LEFT JOIN md_members AS member ON comment.member_id = member.member_id
|
||||
LEFT JOIN md_comments AS parent ON comment.parent_id = parent.comment_id
|
||||
LEFT JOIN md_members AS p_member ON p_member.member_id = parent.member_id
|
||||
|
||||
WHERE comment.document_id = ? ORDER BY comment.comment_id DESC LIMIT 0,10`
|
||||
|
||||
|
||||
offset := (page_index - 1) * page_size
|
||||
|
||||
_,err = o.Raw(sql1,doc_id,offset, page_size).QueryRows(&comments)
|
||||
|
||||
v,err := o.QueryTable(m.TableNameWithPrefix()).Filter("document_id",doc_id).Count()
|
||||
|
||||
if err == nil {
|
||||
totalCount = int(v)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
"github.com/lifei6671/godoc/conf"
|
||||
"github.com/astaxie/beego/orm"
|
||||
)
|
||||
|
||||
type CommentVote struct {
|
||||
VoteId int `orm:"column(vote_id);pk;auto;unique" json:"vote_id"`
|
||||
CommentId int `orm:"column(comment_id);type(int);index" json:"comment_id"`
|
||||
CommentMemberId int `orm:"column(comment_member_id);type(int);index;default(0)" json:"comment_member_id"`
|
||||
VoteMemberId int `orm:"column(vote_member_id);type(int);index" json:"vote_member_id"`
|
||||
VoteState int `orm:"column(vote_state);type(int)" json:"vote_state"`
|
||||
CreateTime time.Time `orm:"column(create_time);type(datetime);auto_now_add" json:"create_time"`
|
||||
}
|
||||
|
||||
// TableName 获取对应数据库表名.
|
||||
func (m *CommentVote) TableName() string {
|
||||
return "comments"
|
||||
}
|
||||
// TableEngine 获取数据使用的引擎.
|
||||
func (m *CommentVote) TableEngine() string {
|
||||
return "INNODB"
|
||||
}
|
||||
|
||||
func (m *CommentVote) TableNameWithPrefix() string {
|
||||
return conf.GetDatabasePrefix() + m.TableName()
|
||||
}
|
||||
func (u *CommentVote) TableUnique() [][]string {
|
||||
return [][]string{
|
||||
[]string{"comment_id", "vote_member_id"},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *CommentVote) InsertOrUpdate() (*CommentVote,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
if m.VoteId > 0 {
|
||||
_,err := o.Update(m)
|
||||
return m,err
|
||||
}else{
|
||||
_,err := o.Insert(m)
|
||||
|
||||
return m,err
|
||||
}
|
||||
}
|
|
@ -59,4 +59,8 @@ func init() {
|
|||
beego.Router("/docs/:key/:id", &controllers.DocumentController{},"*:Read")
|
||||
|
||||
beego.Router("/attach_files/:key/:attach_id",&controllers.DocumentController{},"get:DownloadAttachment")
|
||||
|
||||
beego.Router("/comment/create", &controllers.CommentController{},"post:Create")
|
||||
beego.Router("/comment/lists", &controllers.CommentController{},"get:Lists")
|
||||
beego.Router("/comment/index", &controllers.CommentController{},"*:Index")
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>用户中心 - Powered by MinDoc</title>
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="/static/font-awesome/css/font-awesome.min.css" rel="stylesheet">
|
||||
|
||||
<link href="/static/css/main.css" rel="stylesheet">
|
||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="/static/html5shiv/3.7.3/html5shiv.min.js"></script>
|
||||
<script src="/static/respond.js/1.4.2/respond.min.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<div class="manual-reader">
|
||||
{{template "widgets/header.tpl" .}}
|
||||
<div class="container manual-body">
|
||||
<div class="row">
|
||||
<div class="page-left">
|
||||
<ul class="menu">
|
||||
<li class="active"><a href="{{urlfor "SettingController.Index"}}" class="item"><i class="fa fa-sitemap" aria-hidden="true"></i> 基本信息</a> </li>
|
||||
<li><a href="{{urlfor "SettingController.Password"}}" class="item"><i class="fa fa-user" aria-hidden="true"></i> 修改密码</a> </li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="page-right">
|
||||
<div class="m-box">
|
||||
<div class="box-head">
|
||||
<strong class="box-title">基本信息</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body" style="padding-right: 200px;">
|
||||
<div class="form-left">
|
||||
<form role="form" method="post" id="memberInfoForm">
|
||||
<div class="form-group">
|
||||
<label>用户名</label>
|
||||
<input type="text" class="form-control disabled">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="user-nickname">昵称</label>
|
||||
<input type="text" class="form-control" name="userNickname" id="user-nickname" max="20" placeholder="昵称" value="admin">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="user-email">邮箱<strong class="text-danger">*</strong></label>
|
||||
<input type="email" class="form-control" value="longfei6671@163.com" id="user-email" name="userEmail" max="100" placeholder="邮箱">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>手机号</label>
|
||||
<input type="text" class="form-control" id="user-phone" name="userPhone" maxlength="20" title="手机号码" placeholder="手机号码" value="">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="description">描述</label>
|
||||
<textarea class="form-control" rows="3" title="描述" name="description" id="description" maxlength="500"></textarea>
|
||||
<p style="color: #999;font-size: 12px;">描述不能超过500字</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-success" data-loading-text="保存中...">保存修改</button>
|
||||
<span id="form-error-message" class="error-message"></span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="form-right">
|
||||
<label>
|
||||
<a href="javascript:;" data-toggle="modal" data-target="#upload-logo-panel">
|
||||
<img src="/uploads/user/201612/58649aefa944e_58649aef.JPG" onerror="this.src='https://wiki.iminho.me/static/images/middle.gif'" class="img-circle" alt="头像" style="max-width: 120px;max-height: 120px;" id="headimgurl">
|
||||
</a>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/jquery/1.12.4/jquery.min.js"></script>
|
||||
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue