mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
feat: 添加用户代理字段到评论功能,支持记录用户的用户代理信息
This commit is contained in:
@ -32,6 +32,7 @@ func (cc *CommentController) CreateComment(ctx context.Context, c *app.RequestCo
|
||||
return
|
||||
}
|
||||
req.RemoteAddr = c.RemoteAddr().String()
|
||||
req.UserAgent = string(c.UserAgent())
|
||||
commentID, err := cc.service.CreateComment(ctx, &req)
|
||||
if err != nil {
|
||||
serviceErr := errs.AsServiceError(err)
|
||||
|
@ -23,6 +23,7 @@ type CreateCommentReq struct {
|
||||
ReplyID uint `json:"reply_id"` // 回复的评论ID
|
||||
IsPrivate bool `json:"is_private"` // 是否私密评论,默认false
|
||||
RemoteAddr string `json:"remote_addr"` // 远程地址
|
||||
UserAgent string `json:"user_agent"` // 用户代理
|
||||
}
|
||||
|
||||
type UpdateCommentReq struct {
|
||||
|
@ -15,6 +15,7 @@ type Comment struct {
|
||||
Depth int `gorm:"default:0"` // 评论的层级深度,从0开始计数
|
||||
IsPrivate bool `gorm:"default:false"` // 是否为私密评论,私密评论只有评论者和被评论对象所有者可见
|
||||
RemoteAddr string `gorm:"type:text"` // 远程地址
|
||||
UserAgent string `gorm:"type:text"`
|
||||
LikeCount uint64
|
||||
CommentCount uint64
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ func (cs *CommentService) CreateComment(ctx context.Context, req *dto.CreateComm
|
||||
UserID: currentUser.ID,
|
||||
IsPrivate: req.IsPrivate,
|
||||
RemoteAddr: req.RemoteAddr,
|
||||
UserAgent: req.UserAgent,
|
||||
}
|
||||
|
||||
commentID, err := repo.Comment.CreateComment(comment)
|
||||
|
Reference in New Issue
Block a user