bangumi.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package dao
  2. import (
  3. "context"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/interface/main/space/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/metadata"
  10. )
  11. const (
  12. _build = "0"
  13. _platform = "web"
  14. _bangumiURI = "/api/get_concerned_season"
  15. _bangumiConcernURI = "/api/concern_season"
  16. _bangumiUnConcernURI = "/api/unconcern_season"
  17. )
  18. // BangumiList get bangumi sub list by mid.
  19. func (d *Dao) BangumiList(c context.Context, mid int64, pn, ps int) (data []*model.Bangumi, count int, err error) {
  20. var (
  21. params = url.Values{}
  22. ip = metadata.String(c, metadata.RemoteIP)
  23. )
  24. params.Set("mid", strconv.FormatInt(mid, 10))
  25. params.Set("page", strconv.Itoa(pn))
  26. params.Set("pagesize", strconv.Itoa(ps))
  27. params.Set("build", _build)
  28. params.Set("platform", _platform)
  29. var res struct {
  30. Code int `json:"code"`
  31. Count string `json:"count"`
  32. Result []*model.Bangumi `json:"result"`
  33. }
  34. if err = d.httpR.Get(c, d.bangumiURL, ip, params, &res); err != nil {
  35. log.Error("d.httpR.Get(%s,%d) error(%v)", d.bangumiURL, mid, err)
  36. return
  37. }
  38. if res.Code != ecode.OK.Code() {
  39. log.Error("d.httpR.Get(%s,%d) error(%v)", d.bangumiURL, mid, err)
  40. err = ecode.Int(res.Code)
  41. return
  42. }
  43. data = res.Result
  44. count, _ = strconv.Atoi(res.Count)
  45. return
  46. }
  47. // BangumiConcern bangumi concern.
  48. func (d *Dao) BangumiConcern(c context.Context, mid, seasonID int64) (err error) {
  49. var (
  50. params = url.Values{}
  51. ip = metadata.String(c, metadata.RemoteIP)
  52. )
  53. params.Set("mid", strconv.FormatInt(mid, 10))
  54. params.Set("season_id", strconv.FormatInt(seasonID, 10))
  55. params.Set("build", _build)
  56. params.Set("platform", _platform)
  57. var res struct {
  58. Code int `json:"code"`
  59. }
  60. if err = d.httpW.Post(c, d.bangumiConcernURL, ip, params, &res); err != nil {
  61. log.Error("d.httpW.Post(%s,%d) error(%v)", d.bangumiConcernURL, mid, err)
  62. return
  63. }
  64. if res.Code != ecode.OK.Code() {
  65. log.Error("d.httpW.Post(%s,%d) error(%v)", d.bangumiConcernURL, mid, err)
  66. err = ecode.Int(res.Code)
  67. }
  68. return
  69. }
  70. // BangumiUnConcern bangumi cancel sub.
  71. func (d *Dao) BangumiUnConcern(c context.Context, mid, seasonID int64) (err error) {
  72. var (
  73. params = url.Values{}
  74. ip = metadata.String(c, metadata.RemoteIP)
  75. )
  76. params.Set("mid", strconv.FormatInt(mid, 10))
  77. params.Set("season_id", strconv.FormatInt(seasonID, 10))
  78. params.Set("build", _build)
  79. params.Set("platform", _platform)
  80. var res struct {
  81. Code int `json:"code"`
  82. }
  83. if err = d.httpW.Post(c, d.bangumiUnConcernURL, ip, params, &res); err != nil {
  84. log.Error("d.httpW.Post(%s,%d) error(%v)", d.bangumiUnConcernURL, mid, err)
  85. return
  86. }
  87. if res.Code != ecode.OK.Code() {
  88. log.Error("d.httpW.Post(%s,%d) error(%v)", d.bangumiUnConcernURL, mid, err)
  89. err = ecode.Int(res.Code)
  90. }
  91. return
  92. }