article.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/conf"
  5. artmdl "go-common/app/interface/openplatform/article/model"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. func articleList(c *bm.Context) {
  11. var (
  12. rid, mid int64
  13. pn, ps, sort int
  14. aids []int64
  15. err error
  16. )
  17. param := c.Request.Form
  18. pnStr := param.Get("pn")
  19. psStr := param.Get("ps")
  20. ridStr := param.Get("rid")
  21. aidsStr := param.Get("aids")
  22. sortStr := param.Get("sort")
  23. if midInter, ok := c.Get("mid"); ok {
  24. mid = midInter.(int64)
  25. }
  26. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  27. pn = 1
  28. }
  29. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxArtPageSize {
  30. ps = conf.Conf.Rule.MaxArtPageSize
  31. }
  32. if ridStr != "" {
  33. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil || rid < 0 {
  34. c.JSON(nil, ecode.RequestErr)
  35. return
  36. }
  37. }
  38. if aidsStr != "" {
  39. if aids, err = xstr.SplitInts(aidsStr); err != nil {
  40. c.JSON(nil, ecode.RequestErr)
  41. return
  42. }
  43. }
  44. if sortStr != "" {
  45. if sort, err = strconv.Atoi(sortStr); err != nil || sort < 0 {
  46. c.JSON(nil, ecode.RequestErr)
  47. return
  48. }
  49. sortCheck := false
  50. for _, v := range artmdl.SortFields {
  51. if sort == v {
  52. sortCheck = true
  53. break
  54. }
  55. }
  56. if !sortCheck && sort != 0 {
  57. c.JSON(nil, ecode.RequestErr)
  58. return
  59. }
  60. }
  61. c.JSON(webSvc.ArticleList(c, rid, mid, sort, pn, ps, aids))
  62. }
  63. func articleUpList(c *bm.Context) {
  64. var mid int64
  65. if midInter, ok := c.Get("mid"); ok {
  66. mid = midInter.(int64)
  67. }
  68. c.JSON(webSvc.ArticleUpList(c, mid))
  69. }
  70. func categories(c *bm.Context) {
  71. c.JSON(webSvc.Categories(c))
  72. }
  73. func newCount(c *bm.Context) {
  74. var (
  75. count, pubTime int64
  76. err error
  77. )
  78. pubTimeStr := c.Request.Form.Get("pubtime")
  79. if pubTime, err = strconv.ParseInt(pubTimeStr, 10, 64); err != nil || pubTime < 0 {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. if count, err = webSvc.NewCount(c, pubTime); err != nil {
  84. c.JSON(nil, err)
  85. return
  86. }
  87. c.JSON(struct {
  88. NewCount int64 `json:"new_count"`
  89. }{NewCount: count}, nil)
  90. }
  91. func upMoreArts(c *bm.Context) {
  92. var (
  93. aid int64
  94. err error
  95. )
  96. aidStr := c.Request.Form.Get("aid")
  97. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil || aid <= 0 {
  98. c.JSON(nil, ecode.RequestErr)
  99. return
  100. }
  101. c.JSON(webSvc.UpMoreArts(c, aid))
  102. }