Skip to content

Commit dd42149

Browse files
13791379
authored andcommitted
fix: fix like api http method error
1 parent 5f49dd5 commit dd42149

File tree

7 files changed

+34
-23
lines changed

7 files changed

+34
-23
lines changed

handler/admin/photo.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,3 @@ func (p *PhotoHandler) DeletePhoto(ctx *gin.Context) (interface{}, error) {
122122
func (p *PhotoHandler) ListPhotoTeams(ctx *gin.Context) (interface{}, error) {
123123
return p.PhotoService.ListTeams(ctx)
124124
}
125-
126-
func (p *PhotoHandler) IncreasePhotoLike(ctx *gin.Context) (interface{}, error) {
127-
id, err := util.ParamInt32(ctx, "id")
128-
if err != nil {
129-
return nil, err
130-
}
131-
return nil, p.PhotoService.IncreaseLike(ctx, id)
132-
}

handler/admin/post.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,6 @@ func (p *PostHandler) GetByPostID(ctx *gin.Context) (interface{}, error) {
150150
return postDetailVO, nil
151151
}
152152

153-
func (p *PostHandler) LikePost(ctx *gin.Context) (interface{}, error) {
154-
postID, err := util.ParamInt32(ctx, "postID")
155-
if err != nil {
156-
return nil, err
157-
}
158-
return nil, p.PostService.IncreaseLike(ctx, postID)
159-
}
160-
161153
func (p *PostHandler) CreatePost(ctx *gin.Context) (interface{}, error) {
162154
var postParam param.Post
163155
err := ctx.ShouldBindJSON(&postParam)

handler/content/api/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ func init() {
1111
NewPostHandler,
1212
NewSheetHandler,
1313
NewOptionHandler,
14+
NewPhotoHandler,
1415
)
1516
}

handler/content/api/photo.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package api
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
6+
"github.com/go-sonic/sonic/service"
7+
"github.com/go-sonic/sonic/util"
8+
)
9+
10+
type PhotoHandler struct {
11+
PhotoService service.PhotoService
12+
}
13+
14+
func NewPhotoHandler(photoService service.PhotoService) *PhotoHandler {
15+
return &PhotoHandler{
16+
PhotoService: photoService,
17+
}
18+
}
19+
20+
func (p *PhotoHandler) Like(ctx *gin.Context) (interface{}, error) {
21+
id, err := util.ParamInt32(ctx, "photoID")
22+
if err != nil {
23+
return nil, err
24+
}
25+
return nil, p.PhotoService.IncreaseLike(ctx, id)
26+
}

handler/content/api/post.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,5 @@ func (p *PostHandler) Like(ctx *gin.Context) (interface{}, error) {
182182
if err != nil {
183183
return nil, err
184184
}
185-
err = p.PostService.IncreaseLike(ctx, postID)
186-
if err != nil {
187-
return nil, err
188-
}
189-
return nil, err
185+
return nil, p.PostService.IncreaseLike(ctx, postID)
190186
}

handler/router.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ func (s *Server) RegisterRouters() {
103103
postRouter.GET("/latest", s.wrapHandler(s.PostHandler.ListLatestPosts))
104104
postRouter.GET("/status/:status", s.wrapHandler(s.PostHandler.ListPostsByStatus))
105105
postRouter.GET("/:postID", s.wrapHandler(s.PostHandler.GetByPostID))
106-
postRouter.PUT("/:postID/likes", s.wrapHandler(s.PostHandler.LikePost))
107106
postRouter.POST("", s.wrapHandler(s.PostHandler.CreatePost))
108107
postRouter.PUT("/:postID", s.wrapHandler(s.PostHandler.UpdatePost))
109108
postRouter.PUT("/:postID/status/:status", s.wrapHandler(s.PostHandler.UpdatePostStatus))
@@ -230,7 +229,6 @@ func (s *Server) RegisterRouters() {
230229
photoRouter.DELETE("/:id", s.wrapHandler(s.PhotoHandler.DeletePhoto))
231230
photoRouter.POST("", s.wrapHandler(s.PhotoHandler.CreatePhoto))
232231
photoRouter.PUT("/:id", s.wrapHandler(s.PhotoHandler.UpdatePhoto))
233-
photoRouter.POST("/:id/likes", s.wrapHandler(s.PhotoHandler.IncreasePhotoLike))
234232
photoRouter.GET("/teams", s.wrapHandler(s.PhotoHandler.ListPhotoTeams))
235233
}
236234
{
@@ -327,11 +325,14 @@ func (s *Server) RegisterRouters() {
327325
contentAPIRouter.GET("/journals/:journalID/comments/list_view", s.wrapHandler(s.ContentAPIJournalHandler.ListComment))
328326
contentAPIRouter.POST("/journals/comments", s.wrapHandler(s.ContentAPIJournalHandler.CreateComment))
329327

328+
contentAPIRouter.POST("/photos/:photoID/likes", s.wrapHandler(s.ContentAPIPhotoHandler.Like))
329+
330330
contentAPIRouter.GET("/posts/:postID/comments/top_view", s.wrapHandler(s.ContentAPIPostHandler.ListTopComment))
331331
contentAPIRouter.GET("/posts/:postID/comments/:parentID/children", s.wrapHandler(s.ContentAPIPostHandler.ListChildren))
332332
contentAPIRouter.GET("/posts/:postID/comments/tree_view", s.wrapHandler(s.ContentAPIPostHandler.ListCommentTree))
333333
contentAPIRouter.GET("/posts/:postID/comments/list_view", s.wrapHandler(s.ContentAPIPostHandler.ListComment))
334334
contentAPIRouter.POST("/posts/comments", s.wrapHandler(s.ContentAPIPostHandler.CreateComment))
335+
contentAPIRouter.POST("/posts/:postID/likes", s.wrapHandler(s.ContentAPIPostHandler.Like))
335336

336337
contentAPIRouter.GET("/sheets/:sheetID/comments/top_view", s.wrapHandler(s.ContentAPISheetHandler.ListTopComment))
337338
contentAPIRouter.GET("/sheets/:sheetID/comments/:parentID/children", s.wrapHandler(s.ContentAPISheetHandler.ListChildren))

handler/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type Server struct {
7676
ContentAPIPostHandler *api.PostHandler
7777
ContentAPISheetHandler *api.SheetHandler
7878
ContentAPIOptionHandler *api.OptionHandler
79+
ContentAPIPhotoHandler *api.PhotoHandler
7980
}
8081

8182
type ServerParams struct {
@@ -130,6 +131,7 @@ type ServerParams struct {
130131
ContentAPIPostHandler *api.PostHandler
131132
ContentAPISheetHandler *api.SheetHandler
132133
ContentAPIOptionHandler *api.OptionHandler
134+
ContentAPIPhotoHandler *api.PhotoHandler
133135
}
134136

135137
func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
@@ -194,6 +196,7 @@ func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
194196
ContentAPISheetHandler: param.ContentAPISheetHandler,
195197
ContentAPIOptionHandler: param.ContentAPIOptionHandler,
196198
ContentSearchHandler: param.ContentSearchHandler,
199+
ContentAPIPhotoHandler: param.ContentAPIPhotoHandler,
197200
}
198201
lifecycle.Append(fx.Hook{
199202
OnStop: httpServer.Shutdown,

0 commit comments

Comments
 (0)