|
@@ -8,6 +8,7 @@ import (
|
|
"eta/eta_mini_ht_api/controllers"
|
|
"eta/eta_mini_ht_api/controllers"
|
|
"eta/eta_mini_ht_api/service/user"
|
|
"eta/eta_mini_ht_api/service/user"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "strings"
|
|
)
|
|
)
|
|
|
|
|
|
// UserController Operations about Users
|
|
// UserController Operations about Users
|
|
@@ -91,6 +92,114 @@ type FollowResp struct {
|
|
FollowedType string `json:"FollowedType"`
|
|
FollowedType string `json:"FollowedType"`
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+type FollowAnalystsReq struct {
|
|
|
|
+ AnalystNames string `json:"analystName"`
|
|
|
|
+ FollowType string `json:"followType"`
|
|
|
|
+ Mobile string `json:"mobile"`
|
|
|
|
+ ByName bool `json:"byName"`
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// FollowAnalysts 批量关注研究员
|
|
|
|
+// @Summary 批量关注研究员
|
|
|
|
+// @Description 批量关注研究员
|
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
|
+// @router /followAnalysts [post]
|
|
|
|
+func (u *UserController) FollowAnalysts() {
|
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
|
+ result = u.InitWrapData("")
|
|
|
|
+ followAnalyst := new(FollowAnalystsReq)
|
|
|
|
+ u.GetPostParams(followAnalyst)
|
|
|
|
+ if !authUtils.IsValidMobile(followAnalyst.Mobile) {
|
|
|
|
+ u.FailedResult("手机号非法", result)
|
|
|
|
+ err = exception.New(exception.IllegalPhoneNumber)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var userInfo user.User
|
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
|
+ if userInfo.Mobile != followAnalyst.Mobile {
|
|
|
|
+ u.FailedResult("非当前用户的手机号提交", result)
|
|
|
|
+ err = exception.New(exception.NotCurrentUserError)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ if !checkFollowType(followAnalyst.FollowType) {
|
|
|
|
+ u.FailedResult("关注状态非法", result)
|
|
|
|
+ err = exception.New(exception.IllegalFollowType)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ var msg string
|
|
|
|
+ switch followAnalyst.FollowType {
|
|
|
|
+ case "following":
|
|
|
|
+ msg = "批量关注研究员"
|
|
|
|
+ case "unfollowed":
|
|
|
|
+ msg = "批量取消关注研究员"
|
|
|
|
+ }
|
|
|
|
+ var nameList []string
|
|
|
|
+ names := followAnalyst.AnalystNames
|
|
|
|
+ if strings.HasPrefix(names, ",") {
|
|
|
|
+ names = names[1:len(names)]
|
|
|
|
+ }
|
|
|
|
+ if strings.HasSuffix(names, ",") {
|
|
|
|
+ names = names[0 : len(names)-1]
|
|
|
|
+ }
|
|
|
|
+ if names == "" {
|
|
|
|
+ nameList = []string{}
|
|
|
|
+ } else {
|
|
|
|
+ nameList = strings.Split(names, ",")
|
|
|
|
+ }
|
|
|
|
+ for i := 0; i < len(nameList); i++ {
|
|
|
|
+ nameList[i] = strings.TrimSpace(nameList[i])
|
|
|
|
+ if nameList[i] == "" {
|
|
|
|
+ u.FailedResult("通过研究员姓名关注失败", result)
|
|
|
|
+ err = exception.New(exception.AnalystNameEmptyError)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ err = user.FollowAnalystsByName(userInfo.Id, nameList, followAnalyst.FollowType)
|
|
|
|
+ if err != nil {
|
|
|
|
+ u.FailedResult(msg+"失败", result)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ u.SuccessResult(msg+"成功", nil, result)
|
|
|
|
+ return
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// FollowAnalyst 获取关注状态
|
|
|
|
+// @Summary 获取关注状态
|
|
|
|
+// @Description 获取关注状态
|
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
|
+// @router /followAnalyst [get]
|
|
|
|
+func (u *UserController) CheckFollowStatus(names string) {
|
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
|
+ result = u.InitWrapData("获取关注状态失败")
|
|
|
|
+ var userInfo user.User
|
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
|
+ var nameList []string
|
|
|
|
+ if strings.HasPrefix(names, ",") {
|
|
|
|
+ names = names[1:len(names)]
|
|
|
|
+ }
|
|
|
|
+ if strings.HasSuffix(names, ",") {
|
|
|
|
+ names = names[0 : len(names)-1]
|
|
|
|
+ }
|
|
|
|
+ if names == "" {
|
|
|
|
+ nameList = []string{}
|
|
|
|
+ } else {
|
|
|
|
+ nameList = strings.Split(names, ",")
|
|
|
|
+ }
|
|
|
|
+ for i := 0; i < len(nameList); i++ {
|
|
|
|
+ nameList[i] = strings.TrimSpace(nameList[i])
|
|
|
|
+ }
|
|
|
|
+ list, err := user.CheckFollowStatusByNames(userInfo.Id, nameList)
|
|
|
|
+ if err != nil {
|
|
|
|
+ u.FailedResult("获取关注状态失败", result)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ u.SuccessResult("获取关注状态成功", list, result)
|
|
|
|
+ return
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
// FollowAnalyst 关注研究员
|
|
// FollowAnalyst 关注研究员
|
|
// @Summary 关注研究员
|
|
// @Summary 关注研究员
|
|
// @Description 关注研究员
|
|
// @Description 关注研究员
|
|
@@ -153,9 +262,9 @@ func checkFollowType(followType string) bool {
|
|
return followType == "following" || followType == "unfollowed"
|
|
return followType == "following" || followType == "unfollowed"
|
|
}
|
|
}
|
|
|
|
|
|
-// FollowingAnalysts 关注研究员列表
|
|
|
|
-// @Summary 研究员详情
|
|
|
|
-// @Description 研究员详情
|
|
|
|
|
|
+// FollowingAnalysts 关注研究员
|
|
|
|
+// @Summary 关注研究员
|
|
|
|
+// @Description 关注研究员
|
|
// @Success 200 {object} controllers.BaseResponse
|
|
// @Success 200 {object} controllers.BaseResponse
|
|
// @router /followingAnalysts [get]
|
|
// @router /followingAnalysts [get]
|
|
func (u *UserController) FollowingAnalysts(analystId int) {
|
|
func (u *UserController) FollowingAnalysts(analystId int) {
|