view.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package archive
  2. import (
  3. "context"
  4. "go-common/app/service/main/archive/api"
  5. "go-common/app/service/main/archive/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "github.com/pkg/errors"
  9. )
  10. // View3 view archive with pages pb.
  11. func (d *Dao) View3(c context.Context, aid int64) (v *archive.View3, err error) {
  12. arg := &archive.ArgAid2{Aid: aid}
  13. if v, err = d.arcRPC.View3(c, arg); err != nil {
  14. log.Error("d.arcRPC.View3(%v) error(%+v)", arg, err)
  15. if ecode.Cause(err) == ecode.NothingFound {
  16. err = nil
  17. return
  18. }
  19. }
  20. return
  21. }
  22. // ViewCache get view static data from cache if cache missed from rpc.
  23. func (d *Dao) ViewCache(c context.Context, aid int64) (vs *archive.View3, err error) {
  24. if aid == 0 {
  25. return
  26. }
  27. if vs, err = d.viewCache(c, aid); err != nil {
  28. return
  29. }
  30. if vs != nil && vs.Archive3 != nil && len(vs.Pages) != 0 {
  31. var st *api.Stat
  32. if st, err = d.Stat(c, aid); err != nil {
  33. log.Error("%+v", err)
  34. err = nil
  35. return
  36. }
  37. if st != nil {
  38. vs.Archive3.Stat = archive.Stat3{
  39. Aid: st.Aid,
  40. View: st.View,
  41. Danmaku: st.Danmaku,
  42. Reply: st.Reply,
  43. Fav: st.Fav,
  44. Coin: st.Coin,
  45. Share: st.Share,
  46. NowRank: st.NowRank,
  47. HisRank: st.HisRank,
  48. Like: st.Like,
  49. DisLike: st.DisLike,
  50. }
  51. }
  52. }
  53. return
  54. }
  55. // Description get archive description by aid.
  56. func (d *Dao) Description(c context.Context, aid int64) (desc string, err error) {
  57. arg := &archive.ArgAid{Aid: aid}
  58. if desc, err = d.arcRPC.Description2(c, arg); err != nil {
  59. err = errors.Wrapf(err, "%v", arg)
  60. }
  61. return
  62. }