game.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package http
  2. import (
  3. "go-common/app/admin/main/esports/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. func gameInfo(c *bm.Context) {
  8. v := new(struct {
  9. ID int64 `form:"id" validate:"min=1"`
  10. })
  11. if err := c.Bind(v); err != nil {
  12. return
  13. }
  14. c.JSON(esSvc.GameInfo(c, v.ID))
  15. }
  16. func gameList(c *bm.Context) {
  17. var (
  18. list []*model.Game
  19. cnt int64
  20. err error
  21. )
  22. v := new(struct {
  23. Pn int64 `form:"pn" validate:"min=0"`
  24. Ps int64 `form:"ps" validate:"min=0,max=30"`
  25. Name string `form:"name"`
  26. State int64 `form:"state"`
  27. })
  28. if err = c.Bind(v); err != nil {
  29. return
  30. }
  31. if v.Pn == 0 {
  32. v.Pn = 1
  33. }
  34. if v.Ps == 0 {
  35. v.Ps = 20
  36. }
  37. if list, cnt, err = esSvc.GameList(c, v.Pn, v.Ps, v.Name); err != nil {
  38. c.JSON(nil, err)
  39. return
  40. }
  41. data := make(map[string]interface{}, 2)
  42. page := map[string]int64{
  43. "num": v.Pn,
  44. "size": v.Ps,
  45. "total": cnt,
  46. }
  47. data["page"] = page
  48. data["list"] = list
  49. c.JSON(data, nil)
  50. }
  51. func addGame(c *bm.Context) {
  52. v := new(model.Game)
  53. if err := c.Bind(v); err != nil {
  54. return
  55. }
  56. if v.Plat != 0 {
  57. if _, ok := model.PlatMap[v.Plat]; !ok {
  58. c.JSON(nil, ecode.RequestErr)
  59. return
  60. }
  61. }
  62. if v.Type != 0 {
  63. if _, ok := model.TypeMap[v.Type]; !ok {
  64. c.JSON(nil, ecode.RequestErr)
  65. return
  66. }
  67. }
  68. c.JSON(nil, esSvc.AddGame(c, v))
  69. }
  70. func editGame(c *bm.Context) {
  71. v := new(model.Game)
  72. if err := c.Bind(v); err != nil {
  73. return
  74. }
  75. if v.ID <= 0 {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. if v.Plat != 0 {
  80. if _, ok := model.PlatMap[v.Plat]; !ok {
  81. c.JSON(nil, ecode.RequestErr)
  82. return
  83. }
  84. }
  85. if v.Type != 0 {
  86. if _, ok := model.TypeMap[v.Type]; !ok {
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. }
  91. c.JSON(nil, esSvc.EditGame(c, v))
  92. }
  93. func forbidGame(c *bm.Context) {
  94. v := new(struct {
  95. ID int64 `form:"id" validate:"min=1"`
  96. State int `form:"state" validate:"min=0,max=1"`
  97. })
  98. if err := c.Bind(v); err != nil {
  99. return
  100. }
  101. c.JSON(nil, esSvc.ForbidGame(c, v.ID, v.State))
  102. }
  103. func types(c *bm.Context) {
  104. c.JSON(esSvc.Types(c))
  105. }