feed.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/web-feed/conf"
  6. "go-common/app/interface/main/web-feed/model"
  7. artmdl "go-common/app/interface/openplatform/article/model"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. func feed(c *bm.Context) {
  12. var (
  13. params = c.Request.Form
  14. pn, ps int
  15. mid int64
  16. feeds []*model.Feed
  17. err error
  18. )
  19. pnStr := params.Get("pn")
  20. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  21. pn = 1
  22. }
  23. psStr := params.Get("ps")
  24. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 {
  25. ps = conf.Conf.Feed.DefaultSize
  26. } else if ps > conf.Conf.Feed.MaxSize {
  27. ps = conf.Conf.Feed.MaxSize
  28. }
  29. if midInter, ok := c.Get("mid"); ok {
  30. mid = midInter.(int64)
  31. }
  32. if feeds, err = feedSrv.Feed(c, mid, pn, ps); err != nil {
  33. log.Error("feedSrv.Feed(%d,%d,%d) error(%v)", mid, pn, ps, err)
  34. c.JSON(nil, err)
  35. return
  36. }
  37. c.JSON(feeds, err)
  38. }
  39. func feedUnread(c *bm.Context) {
  40. var (
  41. mid int64
  42. )
  43. if midInter, ok := c.Get("mid"); ok {
  44. mid = midInter.(int64)
  45. }
  46. count, err := feedSrv.UnreadCount(c, mid)
  47. if err != nil {
  48. log.Error("feedSrv.UnreadCount(%d,%v) error(%v)", mid, time.Now(), err)
  49. c.JSON(nil, err)
  50. return
  51. }
  52. c.JSON(struct {
  53. Count int `json:"count"`
  54. }{Count: count}, nil)
  55. }
  56. func articleFeedUnread(c *bm.Context) {
  57. var (
  58. mid int64
  59. )
  60. if midInter, ok := c.Get("mid"); ok {
  61. mid = midInter.(int64)
  62. }
  63. count, err := feedSrv.ArticleUnreadCount(c, mid)
  64. if err != nil {
  65. log.Error("feedSrv.ArticleUnreadCount(%d,%v) error(%v)", mid, time.Now(), err)
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(struct {
  70. Count int `json:"count"`
  71. }{Count: count}, nil)
  72. }
  73. func articleFeed(c *bm.Context) {
  74. var (
  75. params = c.Request.Form
  76. pn, ps int
  77. feeds []*artmdl.Meta
  78. mid int64
  79. err error
  80. )
  81. pnStr := params.Get("pn")
  82. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  83. pn = 1
  84. }
  85. psStr := params.Get("ps")
  86. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 {
  87. ps = conf.Conf.Feed.DefaultSize
  88. } else if ps > conf.Conf.Feed.MaxSize {
  89. ps = conf.Conf.Feed.MaxSize
  90. }
  91. if midInter, ok := c.Get("mid"); ok {
  92. mid = midInter.(int64)
  93. }
  94. if feeds, err = feedSrv.ArticleFeed(c, mid, pn, ps); err != nil {
  95. log.Error("feedSrv.ArticleFeed(%d,%d,%d) error(%v)", mid, pn, ps, err)
  96. c.JSON(nil, err)
  97. return
  98. }
  99. c.JSON(feeds, nil)
  100. }