|
@@ -0,0 +1,132 @@
|
|
|
+package user
|
|
|
+
|
|
|
+import (
|
|
|
+ "eta/eta_mini_ht_api/common/component/cache"
|
|
|
+ "eta/eta_mini_ht_api/common/exception"
|
|
|
+ "eta/eta_mini_ht_api/controllers"
|
|
|
+ "eta/eta_mini_ht_api/service/user"
|
|
|
+ userService "eta/eta_mini_ht_api/service/user"
|
|
|
+)
|
|
|
+
|
|
|
+// BookMarkController Operations about bookmark
|
|
|
+type BookMarkController struct {
|
|
|
+ controllers.BaseController
|
|
|
+ redis *cache.RedisCache
|
|
|
+}
|
|
|
+
|
|
|
+func (u *BookMarkController) Prepare() {
|
|
|
+ u.redis = cache.GetInstance()
|
|
|
+}
|
|
|
+
|
|
|
+type BookMarkReq struct {
|
|
|
+ SourceType string `json:"sourceType"`
|
|
|
+ SourceId int `json:"sourceId"`
|
|
|
+ ChartImage string `json:"chartImage"`
|
|
|
+ ChartInfoId int `json:"chartInfoId"`
|
|
|
+ ChartName string `json:"chartName"`
|
|
|
+}
|
|
|
+
|
|
|
+// BookMark 收藏
|
|
|
+// @Summary 收藏
|
|
|
+// @Description 收藏
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /bookMark [post]
|
|
|
+func (u *BookMarkController) BookMark() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("收藏失败")
|
|
|
+ bookMark := new(BookMarkReq)
|
|
|
+ u.GetPostParams(bookMark)
|
|
|
+ var userInfo user.User
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
+ if bookMark.SourceType == "" {
|
|
|
+ u.FailedResult("收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceType)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if bookMark.SourceId == 0 {
|
|
|
+ u.FailedResult("收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = userService.BookMark(userInfo.Id, bookMark.SourceId, bookMark.SourceType)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.NewWithException(exception.FeedBackError, err.Error())
|
|
|
+ u.FailedResult("收藏失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("收藏成功", nil, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+// UnBookMark 取消收藏
|
|
|
+// @Summary 取消收藏
|
|
|
+// @Description 取消收藏
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /unBookMark [post]
|
|
|
+func (u *BookMarkController) UnBookMark() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("取消收藏失败")
|
|
|
+ bookMark := new(BookMarkReq)
|
|
|
+ u.GetPostParams(bookMark)
|
|
|
+ var userInfo user.User
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
+ if bookMark.SourceType == "" {
|
|
|
+ u.FailedResult("取消收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceType)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if bookMark.SourceId == 0 {
|
|
|
+ u.FailedResult("取消收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = userService.UnBookMark(userInfo.Id, bookMark.SourceId, bookMark.SourceType)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.NewWithException(exception.FeedBackError, err.Error())
|
|
|
+ u.FailedResult("取消收藏失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("收藏成功", nil, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+type CheckBookMarkResp struct {
|
|
|
+ IsBookMarked bool `json:"isBookMarked"`
|
|
|
+}
|
|
|
+
|
|
|
+// CheckBookMark 取消收藏
|
|
|
+// @Summary 取消收藏
|
|
|
+// @Description 取消收藏
|
|
|
+// @Success 200 {object} controllers.BaseResponse
|
|
|
+// @router /checkBookMark [post]
|
|
|
+func (u *BookMarkController) CheckBookMark() {
|
|
|
+ controllers.Wrap(&u.BaseController, func() (result *controllers.WrapData, err error) {
|
|
|
+ result = u.InitWrapData("取消收藏失败")
|
|
|
+ bookMark := new(BookMarkReq)
|
|
|
+ u.GetPostParams(bookMark)
|
|
|
+ var userInfo user.User
|
|
|
+ userInfo = u.Data["user"].(user.User)
|
|
|
+ if bookMark.SourceType == "" {
|
|
|
+ u.FailedResult("获取是否收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceType)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if bookMark.SourceId == 0 {
|
|
|
+ u.FailedResult("获取是否收藏失败", result)
|
|
|
+ err = exception.New(exception.IllegalSourceId)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ isBookMarked, err := userService.CheckBookMarkStatus(userInfo.Id, bookMark.SourceId, bookMark.SourceType)
|
|
|
+ if err != nil {
|
|
|
+ err = exception.NewWithException(exception.FeedBackError, err.Error())
|
|
|
+ u.FailedResult("获取是否收藏失败", result)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ u.SuccessResult("获取是否收藏成功", &CheckBookMarkResp{
|
|
|
+ IsBookMarked: isBookMarked,
|
|
|
+ }, result)
|
|
|
+ return
|
|
|
+ })
|
|
|
+}
|