mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-24 01:56:25 +00:00
feat: implement advanced comment features including reply and like functionality
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 13s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 13s
- Added support for nested comments with reply functionality. - Implemented like/unlike feature for comments and posts. - Enhanced comment DTO to include reply count, like count, and like status. - Updated comment and like services to handle new functionalities. - Created new API endpoints for toggling likes and listing comments. - Improved UI components for comments to support replies and likes with animations. - Added localization for new comment-related messages. - Introduced a TODO list for future enhancements in the comment module.
This commit is contained in:
@ -107,6 +107,16 @@ func (cc *CommentController) GetCommentList(ctx context.Context, c *app.RequestC
|
||||
resps.BadRequest(c, "无效的 target_id")
|
||||
return
|
||||
}
|
||||
commentIDStr := c.Query("comment_id")
|
||||
var commentID uint
|
||||
if commentIDStr != "" {
|
||||
commentIDInt, err := strconv.Atoi(commentIDStr)
|
||||
if err != nil {
|
||||
resps.BadRequest(c, "无效的 comment_id")
|
||||
return
|
||||
}
|
||||
commentID = uint(commentIDInt)
|
||||
}
|
||||
req := dto.GetCommentListReq{
|
||||
Desc: pagination.Desc,
|
||||
OrderBy: pagination.OrderBy,
|
||||
@ -115,6 +125,7 @@ func (cc *CommentController) GetCommentList(ctx context.Context, c *app.RequestC
|
||||
Depth: depthInt,
|
||||
TargetID: uint(targetID),
|
||||
TargetType: c.Query("target_type"),
|
||||
CommentID: commentID,
|
||||
}
|
||||
resp, err := cc.service.GetCommentList(ctx, &req)
|
||||
if err != nil {
|
||||
|
@ -2,15 +2,39 @@ package v1
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/common/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/snowykami/neo-blog/internal/dto"
|
||||
"github.com/snowykami/neo-blog/internal/service"
|
||||
"github.com/snowykami/neo-blog/pkg/errs"
|
||||
"github.com/snowykami/neo-blog/pkg/resps"
|
||||
)
|
||||
|
||||
type LikeController struct{}
|
||||
type LikeController struct {
|
||||
service *service.LikeService
|
||||
}
|
||||
|
||||
func NewLikeController() *LikeController {
|
||||
return &LikeController{}
|
||||
return &LikeController{
|
||||
service: service.NewLikeService(),
|
||||
}
|
||||
}
|
||||
|
||||
func (lc *LikeController) ToggleLike(ctx context.Context, c *app.RequestContext) {
|
||||
// Implementation for creating a like
|
||||
var toggleLikeReq dto.ToggleLikeReq
|
||||
if err := c.BindAndValidate(&toggleLikeReq); err != nil {
|
||||
logrus.Error(err)
|
||||
resps.BadRequest(c, resps.ErrParamInvalid)
|
||||
return
|
||||
}
|
||||
liked, err := lc.service.ToggleLike(ctx, toggleLikeReq.TargetID, toggleLikeReq.TargetType)
|
||||
if err != nil {
|
||||
serviceErr := errs.AsServiceError(err)
|
||||
logrus.Error(serviceErr.Error())
|
||||
resps.Custom(c, serviceErr.Code, serviceErr.Message, nil)
|
||||
return
|
||||
}
|
||||
resps.Ok(c, resps.Success, utils.H{"status": liked})
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package v1
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
"github.com/cloudwego/hertz/pkg/common/utils"
|
||||
"github.com/snowykami/neo-blog/internal/ctxutils"
|
||||
@ -10,7 +12,6 @@ import (
|
||||
"github.com/snowykami/neo-blog/internal/service"
|
||||
"github.com/snowykami/neo-blog/pkg/errs"
|
||||
"github.com/snowykami/neo-blog/pkg/resps"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type UserController struct {
|
||||
|
Reference in New Issue
Block a user