From 2a82f7a328631c824802d34aa4b5f27b0199abec Mon Sep 17 00:00:00 2001 From: doper <849805465@qq.com> Date: Sun, 20 Nov 2022 18:11:06 +0800 Subject: [PATCH] fix(comment): fix comment query param when select --- model/param/comment.go | 6 +++--- service/impl/comment_base.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/model/param/comment.go b/model/param/comment.go index 5741064..f79d090 100644 --- a/model/param/comment.go +++ b/model/param/comment.go @@ -6,9 +6,9 @@ type CommentQuery struct { Page *Sort ContentID *int32 - Keyword *string `json:"keyword"` - CommentStatus *consts.CommentStatus `json:"status"` - ParentID *int32 `json:"parentID"` + Keyword *string `json:"keyword" form:"keyword"` + CommentStatus *consts.CommentStatus `json:"status" form:"status"` + ParentID *int32 `json:"parentID" form:"parentID"` } type Comment struct { diff --git a/service/impl/comment_base.go b/service/impl/comment_base.go index 4342120..1d556d9 100644 --- a/service/impl/comment_base.go +++ b/service/impl/comment_base.go @@ -43,8 +43,8 @@ func (b baseCommentServiceImpl) Page(ctx context.Context, commentQuery param.Com if err != nil { return nil, 0, err } - if commentQuery.Keyword != nil { - commentDO.Where(commentDAL.Content.Like(*commentQuery.Keyword)) + if commentQuery.Keyword != nil && *commentQuery.Keyword != "" { + commentDO.Where(commentDAL.Content.Like("%" + *commentQuery.Keyword + "%")) } if commentQuery.CommentStatus != nil { commentDO.Where(commentDAL.Status.Eq(*commentQuery.CommentStatus))