Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b7b0457

Browse files
committed
app 评论接口
1 parent 09f994d commit b7b0457

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

docs/api.docx

1.54 KB
Binary file not shown.

src/http/controller/app/comment.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2016 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: polaris [email protected]
6+
7+
package app
8+
9+
import (
10+
"http/middleware"
11+
"logic"
12+
"model"
13+
14+
"github.com/labstack/echo"
15+
"github.com/polaris1119/goutils"
16+
)
17+
18+
type CommentController struct{}
19+
20+
func (self CommentController) RegisterRoute(g *echo.Group) {
21+
g.Post("/comment/:objid", self.Create, middleware.NeedLogin(), middleware.Sensivite(), middleware.PublishNotice())
22+
}
23+
24+
// Create 评论(或回复)
25+
func (CommentController) Create(ctx echo.Context) error {
26+
user := ctx.Get("user").(*model.Me)
27+
28+
// 入库
29+
objid := goutils.MustInt(ctx.Param("objid"))
30+
if objid == 0 {
31+
return fail(ctx, "参数有误,请刷新后重试!", 1)
32+
}
33+
comment, err := logic.DefaultComment.Publish(ctx, user.Uid, objid, ctx.FormParams())
34+
if err != nil {
35+
return fail(ctx, "服务器内部错误", 2)
36+
}
37+
38+
return success(ctx, map[string]interface{}{"comment": comment})
39+
}

src/http/controller/app/routes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ func RegisterRoutes(g *echo.Group) {
1616
new(ProjectController).RegisterRoute(g)
1717
new(UserController).RegisterRoute(g)
1818
new(WechatController).RegisterRoute(g)
19+
new(CommentController).RegisterRoute(g)
1920
}

0 commit comments

Comments
 (0)