Преглед на файлове

修改我的留言接口

xiexiaoyuan преди 2 години
родител
ревизия
0072663dbe
променени са 2 файла, в които са добавени 13 реда и са изтрити 3 реда
  1. 9 1
      models/tables/yb_comment/query.go
  2. 4 2
      services/comment/comment.go

+ 9 - 1
models/tables/yb_comment/query.go

@@ -77,7 +77,7 @@ func GetReplyListByReplyCommentId(replyCommentIds []uint64) (list []*YbComment,
 	return
 }
 
-// GetSimpleByCommentId 根据评论ID,查询评论
+// GetSimpleByCommentId 根据留言ID,查询留言
 func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error)  {
 	err = global.DEFAULT_MYSQL.Model(YbComment{}).
 		Select("comment_id, user_id, type, enabled").
@@ -87,3 +87,11 @@ func GetSimpleByCommentId(commentId uint64)(item *YbComment, err error)  {
 	}
 	return
 }
+
+// GetMyLatestComment 获取用户最新的留言
+func GetMyLatestComment(userId uint64) (item *YbComment, err error){
+	err = global.DEFAULT_MYSQL.Model(YbComment{}).
+		Select("comment_id, user_id, type, enabled, is_show_name").
+		Where("user_id = ? and type=1", userId).Order("comment_id desc").First(&item).Error
+	return
+}

+ 4 - 2
services/comment/comment.go

@@ -161,8 +161,10 @@ func MyList(user user.UserInfo,  reportId, reportChapterId, oldReportId, oldRepo
 	if err != nil {
 		return
 	}
-	if len(list.List) > 0 {
-		ret.IsShowName = list.List[0].IsShowName
+	//查询我的最新一条留言是否勾选匿名的设置
+	lastComment, tErr := yb_comment.GetMyLatestComment(user.UserID)
+	if tErr == nil {
+		ret.IsShowName = lastComment.IsShowName
 	}
 	ret.List = list.List
 	return