Browse Source

fix:调整研报收藏回显逻辑

zqbao 11 months ago
parent
commit
aae76b67b0
4 changed files with 15 additions and 54 deletions
  1. 0 43
      controllers/my_report.go
  2. 12 0
      controllers/report.go
  3. 3 2
      models/response/report.go
  4. 0 9
      routers/commentsRouter.go

+ 0 - 43
controllers/my_report.go

@@ -77,49 +77,6 @@ func (this *MyReportController) List() {
 	br.Ret = 200
 }
 
-// @Title IsCollect
-// @Description create users
-// @Param   request	body request.ReportRecordReq true "type json string"
-// @Success 200 {object} models.BaseResponse
-// @Failure 403 {object} models.BaseResponse
-// @router /isCollect [post]
-func (this *MyReportController) IsCollect() {
-	br := new(models.BaseResponse).Init()
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-
-	var req request.MyReportCollectReq
-	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
-		br.Msg = "参数解析失败"
-		br.ErrMsg = "参数解析失败,Err:" + err.Error()
-		return
-	}
-
-	user := this.User
-	if user.Status != 2 {
-		br.Msg = "用户没有权限收藏"
-		return
-	}
-	count, err := models.GetMyReportByUserIdAndReportId(user.UserId, req.ReportId)
-	if err != nil {
-		br.Msg = "查询收藏数量失败"
-		br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
-		return
-	}
-	resp := new(response.MyReportIsCollectResp)
-	if count > 0 {
-		resp.IsCollect = true
-	} else {
-		resp.IsCollect = false
-	}
-	br.Data = resp
-	br.Msg = "查询成功"
-	br.Success = true
-	br.Ret = 200
-}
-
 // @Title 收藏研报
 // @Description 收藏研报
 // @Success 200 {object} models.BaseResponse

+ 12 - 0
controllers/report.go

@@ -41,6 +41,18 @@ func (this *ReportController) Detail() {
 		return
 	}
 
+	count, err := models.GetMyReportByUserIdAndReportId(user.UserId, reportId)
+	if err != nil {
+		br.Msg = "查询收藏数量失败"
+		br.ErrMsg = "查询收藏数量失败,Err:" + err.Error()
+		return
+	}
+	if count > 0 {
+		result.Data.IsCollect = true
+	} else {
+		result.Data.IsCollect = false
+	}
+
 	br.Msg = "查询成功"
 	br.Success = true
 	br.Ret = 200

+ 3 - 2
models/response/report.go

@@ -19,8 +19,9 @@ type ReportResp[T any] struct {
 	ErrMsg string
 }
 type ReportDetailResp struct {
-	Report *models.ReportDetail `description:"报告"`
-	Status int                  `description:"报告状态"`
+	Report    *models.ReportDetail `description:"报告"`
+	Status    int                  `description:"报告状态"`
+	IsCollect bool                 `description:"报告是否收藏"`
 }
 
 type ReportCollectListItem struct {

+ 0 - 9
routers/commentsRouter.go

@@ -97,15 +97,6 @@ func init() {
             Filters: nil,
             Params: nil})
 
-    beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MyReportController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MyReportController"],
-        beego.ControllerComments{
-            Method: "IsCollect",
-            Router: `/isCollect`,
-            AllowHTTPMethods: []string{"post"},
-            MethodParams: param.Make(),
-            Filters: nil,
-            Params: nil})
-
     beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MyReportController"] = append(beego.GlobalControllerRouter["eta/eta_mini_api/controllers:MyReportController"],
         beego.ControllerComments{
             Method: "List",