article.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/openplatform/article/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 meta(c *bm.Context) {
  11. var (
  12. err error
  13. aid int64
  14. am *artmdl.Meta
  15. params = c.Request.Form
  16. )
  17. idStr := params.Get("id")
  18. if aid, err = strconv.ParseInt(idStr, 10, 64); err != nil || aid < 1 {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. if am, err = artSrv.ArticleMeta(c, aid); err != nil {
  23. c.JSON(nil, err)
  24. return
  25. } else if am == nil {
  26. c.JSON(nil, ecode.NothingFound)
  27. return
  28. }
  29. c.JSON(am, nil)
  30. }
  31. func metas(c *bm.Context) {
  32. var (
  33. err error
  34. aids []int64
  35. ams map[int64]*artmdl.Meta
  36. params = c.Request.Form
  37. mid int64
  38. resIDs []int64
  39. )
  40. idsStr := params.Get("ids")
  41. midStr := params.Get("mid")
  42. mid, _ = strconv.ParseInt(midStr, 10, 64)
  43. if aids, err = xstr.SplitInts(idsStr); err != nil || len(aids) < 1 || len(aids) > conf.Conf.Article.MaxArticleMetas {
  44. c.JSON(nil, ecode.RequestErr)
  45. return
  46. }
  47. if ams, err = artSrv.ArticleMetas(c, aids); err != nil {
  48. c.JSON(nil, err)
  49. return
  50. }
  51. if len(ams) == 0 {
  52. c.JSON(nil, ecode.NothingFound)
  53. return
  54. }
  55. if mid > 0 {
  56. for _, artm := range ams {
  57. resIDs = append(resIDs, artm.ID)
  58. }
  59. likeRes, _ := artSrv.HadLikesByMid(c, mid, resIDs)
  60. for _, art := range ams {
  61. isLike := likeRes[art.ID]
  62. if isLike > 0 {
  63. art.IsLike = true
  64. }
  65. }
  66. }
  67. c.JSON(ams, nil)
  68. }
  69. func addCheatFilter(c *bm.Context) {
  70. var (
  71. err error
  72. aid int64
  73. lv int
  74. params = c.Request.Form
  75. )
  76. idStr := params.Get("id")
  77. if aid, err = strconv.ParseInt(idStr, 10, 64); err != nil || aid < 1 {
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. lv, err = strconv.Atoi(params.Get("lv"))
  82. if err != nil {
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. c.JSON(nil, artSrv.AddCheatFilter(c, aid, lv))
  87. }
  88. func delCheatFilter(c *bm.Context) {
  89. var (
  90. err error
  91. aid int64
  92. params = c.Request.Form
  93. )
  94. idStr := params.Get("id")
  95. if aid, err = strconv.ParseInt(idStr, 10, 64); err != nil || aid < 1 {
  96. c.JSON(nil, ecode.RequestErr)
  97. return
  98. }
  99. c.JSON(nil, artSrv.DelCheatFilter(c, aid))
  100. }