savelistmodelogic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package logic
  2. import (
  3. "context"
  4. "errors"
  5. "jyBXBase/entity"
  6. IC "jyBXBase/rpc/init"
  7. "jyBXBase/rpc/internal/svc"
  8. "jyBXBase/rpc/type/bxbase"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type SaveListModeLogic struct {
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. logx.Logger
  15. }
  16. func NewSaveListModeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveListModeLogic {
  17. return &SaveListModeLogic{
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. Logger: logx.WithContext(ctx),
  21. }
  22. }
  23. // SaveListMode 搜索/订阅 列表模式保存
  24. func (l *SaveListModeLogic) SaveListMode(in *bxbase.SaveListModeReq) (res *bxbase.CommonRes, err error) {
  25. res = new(bxbase.CommonRes)
  26. query := map[string]interface{}{
  27. "user_id": in.UserId,
  28. "type": in.Type, // 类型 search-标讯搜索列表 subscribe-订阅列表
  29. }
  30. updateInfo := map[string]interface{}{
  31. "$set": map[string]interface{}{
  32. "mode": int(in.Mode)}, // 列表模式 0-精简列表 1-详细列表
  33. }
  34. // 存在则更新 不存在则保存一条新数据
  35. b := IC.Mgo.Update(entity.ListModeCollection, query, updateInfo, true, false)
  36. if !b {
  37. res.ErrCode = 1
  38. err = errors.New("保存失败")
  39. }
  40. return res, err
  41. }