123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- package collection
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/models/request"
- responseModel "hongze/hongze_yb/models/response"
- "hongze/hongze_yb/services"
- "hongze/hongze_yb/services/collection"
- "hongze/hongze_yb/services/user"
- )
- func List(c *gin.Context) {
- var req request.CollectionListReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- userInfo := user.GetInfoByClaims(c)
- page := services.GetCurrPageByClaims(c)
- pageSize := services.GetPageSizeByClaims(c)
- total, list, e := collection.GetCollectionList(int(userInfo.UserID), req.FromType, page, pageSize, req.Keywords)
- if e != nil {
- response.FailMsg("获取收藏列表失败", "获取收藏列表失败, Err: "+e.Error(), c)
- return
- }
- response.OkData("获取成功", &responseModel.CollectionListResp{
- List: list,
- Paging: responseModel.GetPaging(page, pageSize, total),
- }, c)
- }
- func Collect(c *gin.Context) {
- var req request.CollectionCollectReq
- if c.ShouldBind(&req) != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.CollectionType <= 0 {
- response.Fail("收藏类型有误", c)
- return
- }
- if req.PrimaryId <= 0 {
- response.Fail("参数有误", c)
- return
- }
- userInfo := user.GetInfoByClaims(c)
- if userInfo.UserID <= 0 {
- response.Fail("请登录后操作", c)
- return
- }
- collectionId, e := collection.AddCollection(userInfo, req.CollectionType, req.PrimaryId, req.ExtendId, req.SourceAgent)
- if e != nil {
- response.FailMsg("操作失败", "加入收藏失败, Err: "+e.Error(), c)
- return
- }
- response.OkData("操作成功", collectionId, c)
- }
- func Cancel(c *gin.Context) {
- var req request.CollectionCancelReq
- if c.ShouldBind(&req) != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.CollectionId <= 0 {
- response.Fail("参数有误", c)
- return
- }
- userInfo := user.GetInfoByClaims(c)
- if userInfo.UserID <= 0 {
- response.Fail("请登录后操作", c)
- return
- }
- if e := collection.CancelCollection(int(userInfo.UserID), req.CollectionId); e != nil {
- response.FailMsg("操作失败", "取消收藏失败, Err: "+e.Error(), c)
- return
- }
- response.Ok("操作成功", c)
- }
|