Browse Source

增加研究员关注状态

kobe6258 5 tháng trước cách đây
mục cha
commit
8adc6b4aa9
2 tập tin đã thay đổi với 17 bổ sung13 xóa
  1. 4 1
      domian/report/report_service.go
  2. 13 12
      models/user/user_analyst_follow_list.go

+ 4 - 1
domian/report/report_service.go

@@ -104,9 +104,10 @@ type Anthor struct {
 	Id         int    `json:"id"`
 	Name       string `json:"name"`
 	HeadImgUrl string `json:"headImgUrl"`
+	Following  string `json:"following"`
 }
 
-func GetReportById(reportId int) (ReportDTO ReportDTO, err error) {
+func GetReportById(reportId int, userId int) (ReportDTO ReportDTO, err error) {
 	report, err := reportDao.GetReportById(reportId)
 	if err != nil {
 		return
@@ -126,12 +127,14 @@ func GetReportById(reportId int) (ReportDTO ReportDTO, err error) {
 					Id:         0,
 					Name:       name,
 					HeadImgUrl: "",
+					Following:  string(userDao.Unfollowed),
 				}
 			} else {
 				item = Anthor{
 					Id:         author.Id,
 					Name:       author.Name,
 					HeadImgUrl: author.HeadImgUrl,
+					Following:  userDao.GetFollowing(userId, author.Id),
 				}
 			}
 			authorList = append(authorList, item)

+ 13 - 12
models/user/user_analyst_follow_list.go

@@ -133,18 +133,7 @@ func GetFollowingAnalystList(userId int) (list []UserAnalystFollowList, err erro
 	err = db.Select(listColumns).Where("user_id = ? and followed = ?", userId, Following).Order("followed_time desc").Find(&list).Error
 	return
 }
-func GetFollowing(userId int, analystId int) string {
-	db := models.Main()
-	var dbFollow UserAnalystFollowList
-	err := db.Model(&UserAnalystFollowList{}).Where("user_id = ? and financial_analyst_id = ?", userId, analystId).First(&dbFollow).Error
-	if err != nil {
-		if !errors.Is(err, gorm.ErrRecordNotFound) {
-			logger.Error("查询用户关注状态失败:%v", err)
-		}
-		return string(Unfollowed)
-	}
-	return string(dbFollow.Followed)
-}
+
 func FollowAnalyst(follow UserAnalystFollowList) (err error) {
 	if follow.Followed == "" {
 		err = errors.New("关注状态非法")
@@ -188,3 +177,15 @@ func GetFollowed(userId int, analystId int) string {
 	}
 	return string(record.Followed)
 }
+func GetFollowing(userId int, analystId int) string {
+	db := models.Main()
+	var dbFollow UserAnalystFollowList
+	err := db.Model(&UserAnalystFollowList{}).Where("user_id = ? and financial_analyst_id = ?", userId, analystId).First(&dbFollow).Error
+	if err != nil {
+		if !errors.Is(err, gorm.ErrRecordNotFound) {
+			logger.Error("查询用户关注状态失败:%v", err)
+		}
+		return string(Unfollowed)
+	}
+	return string(dbFollow.Followed)
+}