up_card.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "go-common/app/service/main/up/model"
  6. "go-common/app/service/main/up/service"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. "go-common/library/net/http/blademaster"
  10. )
  11. func getCardInfo(ctx *blademaster.Context) {
  12. var r = new(model.GetCardByMidArg)
  13. if err := ctx.Bind(r); err != nil {
  14. log.Error("request argument bind fail, err=%v", err)
  15. err = ecode.RequestErr
  16. return
  17. }
  18. // check params
  19. mid := r.Mid
  20. if mid <= 0 {
  21. log.Error("getCardInfo error mid (%d)", mid)
  22. ctx.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. card, err := Svc.GetCardInfo(ctx, mid)
  26. if err != nil {
  27. service.BmHTTPErrorWithMsg(ctx, ecode.ServerErr, err.Error())
  28. return
  29. }
  30. ctx.JSON(card, err)
  31. }
  32. func listCardBase(ctx *blademaster.Context) {
  33. mids, err := Svc.ListCardBase(ctx)
  34. if err != nil {
  35. service.BmHTTPErrorWithMsg(ctx, ecode.ServerErr, err.Error())
  36. return
  37. }
  38. ctx.JSON(map[string]interface{}{
  39. "mids": mids,
  40. }, nil)
  41. }
  42. func listCardDetail(ctx *blademaster.Context) {
  43. arg := new(model.ListUpCardInfoArg)
  44. if err := ctx.Bind(arg); err != nil {
  45. log.Error("request argument bind fail, err=%v", err)
  46. err = ecode.RequestErr
  47. return
  48. }
  49. offset := (arg.Pn - 1) * arg.Ps
  50. cards, total, err := Svc.ListCardDetail(ctx, offset, arg.Ps)
  51. if err != nil {
  52. service.BmHTTPErrorWithMsg(ctx, ecode.ServerErr, err.Error())
  53. return
  54. }
  55. var data = &model.UpCardInfoPage{
  56. Cards: cards,
  57. Page: &model.Pager{Num: arg.Pn, Size: uint(len(cards)), Total: total},
  58. }
  59. ctx.JSON(data, nil)
  60. }
  61. func listCardByMids(ctx *blademaster.Context) {
  62. arg := new(model.ListCardByMidsArg)
  63. if err := ctx.Bind(arg); err != nil {
  64. log.Error("request argument bind fail, err=%v", err)
  65. err = ecode.RequestErr
  66. return
  67. }
  68. var mids []int64
  69. midStrs := strings.Split(arg.Mids, ",")
  70. for _, midStr := range midStrs {
  71. mid, e := strconv.ParseInt(strings.Trim(midStr, " \n"), 10, 64)
  72. if e != nil {
  73. continue
  74. }
  75. mids = append(mids, mid)
  76. }
  77. cards, err := Svc.GetCardInfoByMids(ctx, mids)
  78. if err != nil {
  79. service.BmHTTPErrorWithMsg(ctx, ecode.ServerErr, err.Error())
  80. return
  81. }
  82. ctx.JSON(cards, nil)
  83. }