album.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. _albumCountURI = "/link_draw/v1/doc/upload_count"
  13. _albumListURI = "/link_draw/v1/doc/doc_list"
  14. )
  15. // AlbumCount get album count.
  16. func (d *Dao) AlbumCount(c context.Context, mid int64) (count int64, err error) {
  17. var (
  18. params = url.Values{}
  19. ip = metadata.String(c, metadata.RemoteIP)
  20. )
  21. params.Set("uid", strconv.FormatInt(mid, 10))
  22. var res struct {
  23. Code int `json:"code"`
  24. Data model.AlbumCount `json:"data"`
  25. }
  26. if err = d.httpR.Get(c, d.albumCountURL, ip, params, &res); err != nil {
  27. log.Error("d.httpR.Get(%s) mid(%d) error(%v)", d.albumCountURL, mid, err)
  28. return
  29. }
  30. if res.Code != ecode.OK.Code() {
  31. log.Error("d.httpR.Get(%s) mid(%d) code(%d)", d.albumCountURL, mid, res.Code)
  32. err = ecode.Int(res.Code)
  33. return
  34. }
  35. count = res.Data.AllCount
  36. return
  37. }
  38. // AlbumList get album list.
  39. func (d *Dao) AlbumList(c context.Context, mid int64, pn, ps int) (list []*model.Album, err error) {
  40. var (
  41. params = url.Values{}
  42. ip = metadata.String(c, metadata.RemoteIP)
  43. )
  44. params.Set("uid", strconv.FormatInt(mid, 10))
  45. params.Set("page_num", strconv.Itoa(pn))
  46. params.Set("page_size", strconv.Itoa(ps))
  47. var res struct {
  48. Code int `json:"code"`
  49. Data struct {
  50. Items []*model.Album `json:"items"`
  51. } `json:"data"`
  52. }
  53. if err = d.httpR.Get(c, d.albumListURL, ip, params, &res); err != nil {
  54. log.Error("d.httpR.Get(%s) mid(%d) error(%v)", d.albumListURL, mid, err)
  55. return
  56. }
  57. if res.Code != ecode.OK.Code() {
  58. log.Error("d.httpR.Get(%s) mid(%d) code(%d)", d.albumListURL, mid, res.Code)
  59. err = ecode.Int(res.Code)
  60. return
  61. }
  62. list = res.Data.Items
  63. return
  64. }