Merge branch 'master' of github.com:popstk/sonic

pull/146/head
popstk 2 years ago
commit e4e7fe546d

@ -122,11 +122,3 @@ func (p *PhotoHandler) DeletePhoto(ctx *gin.Context) (interface{}, error) {
func (p *PhotoHandler) ListPhotoTeams(ctx *gin.Context) (interface{}, error) { func (p *PhotoHandler) ListPhotoTeams(ctx *gin.Context) (interface{}, error) {
return p.PhotoService.ListTeams(ctx) return p.PhotoService.ListTeams(ctx)
} }
func (p *PhotoHandler) IncreasePhotoLike(ctx *gin.Context) (interface{}, error) {
id, err := util.ParamInt32(ctx, "id")
if err != nil {
return nil, err
}
return nil, p.PhotoService.IncreaseLike(ctx, id)
}

@ -150,14 +150,6 @@ func (p *PostHandler) GetByPostID(ctx *gin.Context) (interface{}, error) {
return postDetailVO, nil return postDetailVO, nil
} }
func (p *PostHandler) LikePost(ctx *gin.Context) (interface{}, error) {
postID, err := util.ParamInt32(ctx, "postID")
if err != nil {
return nil, err
}
return nil, p.PostService.IncreaseLike(ctx, postID)
}
func (p *PostHandler) CreatePost(ctx *gin.Context) (interface{}, error) { func (p *PostHandler) CreatePost(ctx *gin.Context) (interface{}, error) {
var postParam param.Post var postParam param.Post
err := ctx.ShouldBindJSON(&postParam) err := ctx.ShouldBindJSON(&postParam)

@ -11,5 +11,6 @@ func init() {
NewPostHandler, NewPostHandler,
NewSheetHandler, NewSheetHandler,
NewOptionHandler, NewOptionHandler,
NewPhotoHandler,
) )
} }

@ -0,0 +1,26 @@
package api
import (
"github.com/gin-gonic/gin"
"github.com/go-sonic/sonic/service"
"github.com/go-sonic/sonic/util"
)
type PhotoHandler struct {
PhotoService service.PhotoService
}
func NewPhotoHandler(photoService service.PhotoService) *PhotoHandler {
return &PhotoHandler{
PhotoService: photoService,
}
}
func (p *PhotoHandler) Like(ctx *gin.Context) (interface{}, error) {
id, err := util.ParamInt32(ctx, "photoID")
if err != nil {
return nil, err
}
return nil, p.PhotoService.IncreaseLike(ctx, id)
}

@ -182,9 +182,5 @@ func (p *PostHandler) Like(ctx *gin.Context) (interface{}, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = p.PostService.IncreaseLike(ctx, postID) return nil, p.PostService.IncreaseLike(ctx, postID)
if err != nil {
return nil, err
}
return nil, err
} }

@ -103,7 +103,6 @@ func (s *Server) RegisterRouters() {
postRouter.GET("/latest", s.wrapHandler(s.PostHandler.ListLatestPosts)) postRouter.GET("/latest", s.wrapHandler(s.PostHandler.ListLatestPosts))
postRouter.GET("/status/:status", s.wrapHandler(s.PostHandler.ListPostsByStatus)) postRouter.GET("/status/:status", s.wrapHandler(s.PostHandler.ListPostsByStatus))
postRouter.GET("/:postID", s.wrapHandler(s.PostHandler.GetByPostID)) postRouter.GET("/:postID", s.wrapHandler(s.PostHandler.GetByPostID))
postRouter.PUT("/:postID/likes", s.wrapHandler(s.PostHandler.LikePost))
postRouter.POST("", s.wrapHandler(s.PostHandler.CreatePost)) postRouter.POST("", s.wrapHandler(s.PostHandler.CreatePost))
postRouter.PUT("/:postID", s.wrapHandler(s.PostHandler.UpdatePost)) postRouter.PUT("/:postID", s.wrapHandler(s.PostHandler.UpdatePost))
postRouter.PUT("/:postID/status/:status", s.wrapHandler(s.PostHandler.UpdatePostStatus)) postRouter.PUT("/:postID/status/:status", s.wrapHandler(s.PostHandler.UpdatePostStatus))
@ -230,7 +229,6 @@ func (s *Server) RegisterRouters() {
photoRouter.DELETE("/:id", s.wrapHandler(s.PhotoHandler.DeletePhoto)) photoRouter.DELETE("/:id", s.wrapHandler(s.PhotoHandler.DeletePhoto))
photoRouter.POST("", s.wrapHandler(s.PhotoHandler.CreatePhoto)) photoRouter.POST("", s.wrapHandler(s.PhotoHandler.CreatePhoto))
photoRouter.PUT("/:id", s.wrapHandler(s.PhotoHandler.UpdatePhoto)) photoRouter.PUT("/:id", s.wrapHandler(s.PhotoHandler.UpdatePhoto))
photoRouter.POST("/:id/likes", s.wrapHandler(s.PhotoHandler.IncreasePhotoLike))
photoRouter.GET("/teams", s.wrapHandler(s.PhotoHandler.ListPhotoTeams)) photoRouter.GET("/teams", s.wrapHandler(s.PhotoHandler.ListPhotoTeams))
} }
{ {
@ -327,11 +325,14 @@ func (s *Server) RegisterRouters() {
contentAPIRouter.GET("/journals/:journalID/comments/list_view", s.wrapHandler(s.ContentAPIJournalHandler.ListComment)) contentAPIRouter.GET("/journals/:journalID/comments/list_view", s.wrapHandler(s.ContentAPIJournalHandler.ListComment))
contentAPIRouter.POST("/journals/comments", s.wrapHandler(s.ContentAPIJournalHandler.CreateComment)) contentAPIRouter.POST("/journals/comments", s.wrapHandler(s.ContentAPIJournalHandler.CreateComment))
contentAPIRouter.POST("/photos/:photoID/likes", s.wrapHandler(s.ContentAPIPhotoHandler.Like))
contentAPIRouter.GET("/posts/:postID/comments/top_view", s.wrapHandler(s.ContentAPIPostHandler.ListTopComment)) contentAPIRouter.GET("/posts/:postID/comments/top_view", s.wrapHandler(s.ContentAPIPostHandler.ListTopComment))
contentAPIRouter.GET("/posts/:postID/comments/:parentID/children", s.wrapHandler(s.ContentAPIPostHandler.ListChildren)) contentAPIRouter.GET("/posts/:postID/comments/:parentID/children", s.wrapHandler(s.ContentAPIPostHandler.ListChildren))
contentAPIRouter.GET("/posts/:postID/comments/tree_view", s.wrapHandler(s.ContentAPIPostHandler.ListCommentTree)) contentAPIRouter.GET("/posts/:postID/comments/tree_view", s.wrapHandler(s.ContentAPIPostHandler.ListCommentTree))
contentAPIRouter.GET("/posts/:postID/comments/list_view", s.wrapHandler(s.ContentAPIPostHandler.ListComment)) contentAPIRouter.GET("/posts/:postID/comments/list_view", s.wrapHandler(s.ContentAPIPostHandler.ListComment))
contentAPIRouter.POST("/posts/comments", s.wrapHandler(s.ContentAPIPostHandler.CreateComment)) contentAPIRouter.POST("/posts/comments", s.wrapHandler(s.ContentAPIPostHandler.CreateComment))
contentAPIRouter.POST("/posts/:postID/likes", s.wrapHandler(s.ContentAPIPostHandler.Like))
contentAPIRouter.GET("/sheets/:sheetID/comments/top_view", s.wrapHandler(s.ContentAPISheetHandler.ListTopComment)) contentAPIRouter.GET("/sheets/:sheetID/comments/top_view", s.wrapHandler(s.ContentAPISheetHandler.ListTopComment))
contentAPIRouter.GET("/sheets/:sheetID/comments/:parentID/children", s.wrapHandler(s.ContentAPISheetHandler.ListChildren)) contentAPIRouter.GET("/sheets/:sheetID/comments/:parentID/children", s.wrapHandler(s.ContentAPISheetHandler.ListChildren))

@ -76,6 +76,7 @@ type Server struct {
ContentAPIPostHandler *api.PostHandler ContentAPIPostHandler *api.PostHandler
ContentAPISheetHandler *api.SheetHandler ContentAPISheetHandler *api.SheetHandler
ContentAPIOptionHandler *api.OptionHandler ContentAPIOptionHandler *api.OptionHandler
ContentAPIPhotoHandler *api.PhotoHandler
} }
type ServerParams struct { type ServerParams struct {
@ -130,6 +131,7 @@ type ServerParams struct {
ContentAPIPostHandler *api.PostHandler ContentAPIPostHandler *api.PostHandler
ContentAPISheetHandler *api.SheetHandler ContentAPISheetHandler *api.SheetHandler
ContentAPIOptionHandler *api.OptionHandler ContentAPIOptionHandler *api.OptionHandler
ContentAPIPhotoHandler *api.PhotoHandler
} }
func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server { func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
@ -194,6 +196,7 @@ func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
ContentAPISheetHandler: param.ContentAPISheetHandler, ContentAPISheetHandler: param.ContentAPISheetHandler,
ContentAPIOptionHandler: param.ContentAPIOptionHandler, ContentAPIOptionHandler: param.ContentAPIOptionHandler,
ContentSearchHandler: param.ContentSearchHandler, ContentSearchHandler: param.ContentSearchHandler,
ContentAPIPhotoHandler: param.ContentAPIPhotoHandler,
} }
lifecycle.Append(fx.Hook{ lifecycle.Append(fx.Hook{
OnStop: httpServer.Shutdown, OnStop: httpServer.Shutdown,

@ -147,7 +147,7 @@ func (a *attachmentServiceImpl) Upload(ctx context.Context, fileHeader *multipar
WithStatus(xerr.StatusBadRequest). WithStatus(xerr.StatusBadRequest).
WithMsg("附件路径为 " + attachmentDTO.Path + " 已经存在") WithMsg("附件路径为 " + attachmentDTO.Path + " 已经存在")
} }
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { if !errors.Is(err, gorm.ErrRecordNotFound) {
return nil, WrapDBErr(err) return nil, WrapDBErr(err)
} }
attachmentEntity := &entity.Attachment{ attachmentEntity := &entity.Attachment{

Loading…
Cancel
Save