app_article.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. bm "go-common/library/net/http/blademaster"
  5. "go-common/library/net/metadata"
  6. "strconv"
  7. )
  8. func appArticleList(c *bm.Context) {
  9. params := c.Request.Form
  10. pnStr := params.Get("pn")
  11. psStr := params.Get("ps")
  12. sortStr := params.Get("sort")
  13. groupStr := params.Get("group")
  14. categoryStr := params.Get("category")
  15. ip := metadata.String(c, metadata.RemoteIP)
  16. // check user
  17. midStr, _ := c.Get("mid")
  18. mid := midStr.(int64)
  19. if mid <= 0 {
  20. c.JSON(nil, ecode.CreativeNotLogin)
  21. return
  22. }
  23. pn, err := strconv.Atoi(pnStr)
  24. if err != nil || pn < 1 {
  25. pn = 1
  26. }
  27. ps, err := strconv.Atoi(psStr)
  28. if err != nil || ps <= 10 {
  29. ps = 20
  30. }
  31. sort, err := strconv.Atoi(sortStr)
  32. if err != nil || sort < 0 {
  33. sort = 0
  34. }
  35. group, err := strconv.Atoi(groupStr)
  36. if err != nil || group < 0 {
  37. group = 0
  38. }
  39. category, err := strconv.Atoi(categoryStr)
  40. if err != nil || category < 0 {
  41. category = 0
  42. }
  43. arts, err := artSvc.Articles(c, mid, int(pn), int(ps), sort, group, category, ip)
  44. if err != nil {
  45. c.JSON(nil, err)
  46. return
  47. }
  48. c.JSON(arts, nil)
  49. }