newlist.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/web/conf"
  5. "go-common/app/service/main/archive/api"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. func newList(c *bm.Context) {
  11. var (
  12. rid, pn, ps, tp, count int
  13. rs []*api.Arc
  14. err error
  15. )
  16. params := c.Request.Form
  17. ridStr := params.Get("rid")
  18. pnStr := params.Get("pn")
  19. psStr := params.Get("ps")
  20. tpStr := params.Get("type")
  21. if ridStr != "" {
  22. if rid, err = strconv.Atoi(ridStr); err != nil || rid < 0 {
  23. c.JSON(nil, ecode.RequestErr)
  24. return
  25. }
  26. }
  27. if pn, err = strconv.Atoi(pnStr); err != nil || pn < 1 {
  28. pn = 1
  29. }
  30. if ps, err = strconv.Atoi(psStr); err != nil || ps < 1 || ps > conf.Conf.Rule.MaxArcsPageSize {
  31. ps = conf.Conf.Rule.MaxArcsPageSize
  32. }
  33. if tpStr != "" {
  34. if tp, err = strconv.Atoi(tpStr); err != nil {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. }
  39. if rs, count, err = webSvc.NewList(c, int32(rid), int8(tp), pn, ps); err != nil {
  40. c.JSON(nil, err)
  41. log.Error("webSvc.Newlist(%d,%d,%d) error(%v)", rid, pn, ps, err)
  42. return
  43. }
  44. data := make(map[string]interface{}, 2)
  45. page := map[string]int{
  46. "num": pn,
  47. "size": ps,
  48. "count": count,
  49. }
  50. data["page"] = page
  51. data["archives"] = rs
  52. c.JSON(data, nil)
  53. }