users.go 706 B

123456789101112131415161718192021222324252627282930313233
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/interface/openplatform/article/model"
  5. "go-common/library/ecode"
  6. )
  7. // UserNoticeState .
  8. func (s *Service) UserNoticeState(c context.Context, mid int64) (res model.NoticeState, err error) {
  9. state, err := s.dao.NoticeState(c, mid)
  10. if err != nil {
  11. return
  12. }
  13. res = model.NewNoticeState(state)
  14. return
  15. }
  16. // UpdateUserNoticeState .
  17. func (s *Service) UpdateUserNoticeState(c context.Context, mid int64, typ string) (err error) {
  18. state, err := s.UserNoticeState(c, mid)
  19. if err != nil {
  20. return
  21. }
  22. if _, ok := state[typ]; !ok {
  23. err = ecode.RequestErr
  24. return
  25. }
  26. state[typ] = true
  27. err = s.dao.UpdateNoticeState(c, mid, state.ToInt64())
  28. return
  29. }