elec.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package http
  2. import (
  3. "net/http"
  4. api "go-common/app/service/main/ugcpay-rank/api/http"
  5. "go-common/app/service/main/ugcpay-rank/internal/conf"
  6. "go-common/app/service/main/ugcpay-rank/internal/model"
  7. bm "go-common/library/net/http/blademaster"
  8. "github.com/json-iterator/go"
  9. )
  10. const (
  11. _contentTypeJSON = "application/json; charset=utf-8"
  12. )
  13. func elecMonthUP(ctx *bm.Context) {
  14. var (
  15. err error
  16. arg = &api.ArgRankElecMonthUP{}
  17. resp = &api.RetRankElecMonthUP{
  18. Data: &api.RespRankElecMonthUP{},
  19. }
  20. upRank *model.RankElecUPProto
  21. bytes []byte
  22. )
  23. if err = ctx.Bind(arg); err != nil {
  24. return
  25. }
  26. if arg.RankSize <= 0 || arg.RankSize > conf.Conf.Biz.ElecUPRankSize {
  27. arg.RankSize = conf.Conf.Biz.ElecUPRankSize
  28. }
  29. if upRank, err = svc.ElecMonthRankUP(ctx, arg.UPMID, arg.RankSize); err != nil {
  30. ctx.JSON(nil, err)
  31. return
  32. }
  33. resp.Data.Parse(upRank)
  34. if bytes, err = jsoniter.ConfigFastest.Marshal(resp); err != nil {
  35. ctx.JSON(nil, err)
  36. return
  37. }
  38. ctx.Bytes(http.StatusOK, _contentTypeJSON, bytes)
  39. }
  40. func elecMonth(ctx *bm.Context) {
  41. var (
  42. err error
  43. arg = &api.ArgRankElecMonth{}
  44. resp = &api.RetRankElecMonth{
  45. Data: &api.RespRankElecMonth{},
  46. }
  47. upRank *model.RankElecUPProto
  48. avRank *model.RankElecAVProto
  49. bytes []byte
  50. )
  51. if err = ctx.Bind(arg); err != nil {
  52. return
  53. }
  54. if arg.RankSize <= 0 || arg.RankSize > conf.Conf.Biz.ElecAVRankSize {
  55. arg.RankSize = conf.Conf.Biz.ElecAVRankSize
  56. }
  57. if upRank, err = svc.ElecMonthRankUP(ctx, arg.UPMID, arg.RankSize); err != nil {
  58. ctx.JSON(nil, err)
  59. return
  60. }
  61. if avRank, err = svc.ElecMonthRankAV(ctx, arg.UPMID, arg.AVID, arg.RankSize); err != nil {
  62. ctx.JSON(nil, err)
  63. return
  64. }
  65. resp.Data.Parse(avRank, upRank)
  66. if bytes, err = jsoniter.ConfigFastest.Marshal(resp); err != nil {
  67. ctx.JSON(nil, err)
  68. return
  69. }
  70. ctx.Bytes(http.StatusOK, _contentTypeJSON, bytes)
  71. }
  72. func elecAllAV(ctx *bm.Context) {
  73. var (
  74. err error
  75. arg = &api.ArgRankElecMonth{}
  76. resp = &api.RetRankElecAllAV{
  77. Data: &api.RespRankElecAllAV{},
  78. }
  79. avRank *model.RankElecAVProto
  80. bytes []byte
  81. )
  82. if err = ctx.Bind(arg); err != nil {
  83. return
  84. }
  85. if arg.RankSize <= 0 || arg.RankSize > conf.Conf.Biz.ElecAVRankSize {
  86. arg.RankSize = conf.Conf.Biz.ElecAVRankSize
  87. }
  88. if avRank, err = svc.ElecTotalRankAV(ctx, arg.UPMID, arg.AVID, arg.RankSize); err != nil {
  89. ctx.JSON(nil, err)
  90. return
  91. }
  92. resp.Data.Parse(avRank)
  93. if bytes, err = jsoniter.ConfigFastest.Marshal(resp); err != nil {
  94. ctx.JSON(nil, err)
  95. return
  96. }
  97. ctx.Bytes(http.StatusOK, _contentTypeJSON, bytes)
  98. }