channel.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package v1
  2. import (
  3. "dsbqj-admin/app/service"
  4. "dsbqj-admin/pkg/app"
  5. "dsbqj-admin/pkg/e"
  6. "dsbqj-admin/pkg/serializer"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func ChannelAll(c *gin.Context) {
  11. var appG = app.Gin{C: c}
  12. service := service.GameChannelService{}
  13. if err := c.ShouldBind(&service); err == nil {
  14. if res, err := service.All(); err != nil {
  15. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  16. } else {
  17. appG.Response(http.StatusOK, e.SUCCESS, res)
  18. }
  19. } else {
  20. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  21. }
  22. }
  23. func PlatformList(c *gin.Context) {
  24. var g = app.Gin{C: c}
  25. v, err := (&service.PlatformListService{}).List()
  26. if err != nil {
  27. g.Response(http.StatusOK, e.ERROR, err.Error())
  28. return
  29. }
  30. g.Response(http.StatusOK, e.SUCCESS, serializer.BuildPlatformList(v))
  31. }
  32. func PlatformCreate(c *gin.Context) {
  33. var g = app.Gin{C: c}
  34. var s service.PlatformCreateService
  35. if err := c.ShouldBindJSON(&s); err != nil {
  36. g.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  37. return
  38. }
  39. g.Response(http.StatusOK, e.SUCCESS, s.Create())
  40. }
  41. func PlatformUpdate(c *gin.Context) {
  42. var g = app.Gin{C: c}
  43. var s service.PlatformUpdateService
  44. if err := c.ShouldBindJSON(&s); err != nil {
  45. g.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  46. return
  47. }
  48. g.Response(http.StatusOK, e.SUCCESS, s.Update())
  49. }
  50. func PlatformDelete(c *gin.Context) {
  51. var g = app.Gin{C: c}
  52. var s service.PlatformDeleteService
  53. if err := c.ShouldBindJSON(&s); err != nil {
  54. g.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  55. return
  56. }
  57. g.Response(http.StatusOK, e.SUCCESS, s.Delete())
  58. }
  59. // ChannelList 渠道列表
  60. func ChannelList(c *gin.Context) {
  61. var appG = app.Gin{C: c}
  62. var svc service.ChannelListService
  63. if err := c.ShouldBindQuery(&svc); err != nil {
  64. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  65. return
  66. }
  67. res, err := svc.List()
  68. if err != nil {
  69. appG.Response(http.StatusOK, e.ERROR, err.Error())
  70. return
  71. }
  72. appG.Response(http.StatusOK, e.SUCCESS, res)
  73. }
  74. // ChannelCreate 渠道新增
  75. func ChannelCreate(c *gin.Context) {
  76. var appG = app.Gin{C: c}
  77. var svc service.ChannelCreateService
  78. if err := c.ShouldBindJSON(&svc); err != nil {
  79. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  80. return
  81. }
  82. if err := svc.Create(); err != nil {
  83. appG.Response(http.StatusOK, e.ERROR, err.Error())
  84. return
  85. }
  86. appG.Response(http.StatusOK, e.SUCCESS, nil)
  87. }
  88. // ChannelUpdate 渠道修改
  89. func ChannelUpdate(c *gin.Context) {
  90. var appG = app.Gin{C: c}
  91. var svc service.ChannelUpdateService
  92. if err := c.ShouldBindJSON(&svc); err != nil {
  93. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  94. return
  95. }
  96. if err := svc.Update(); err != nil {
  97. appG.Response(http.StatusOK, e.ERROR, err.Error())
  98. return
  99. }
  100. appG.Response(http.StatusOK, e.SUCCESS, nil)
  101. }
  102. // ChannelDelete 渠道删除
  103. func ChannelDelete(c *gin.Context) {
  104. var appG = app.Gin{C: c}
  105. var svc service.ChannelDeleteService
  106. if err := c.ShouldBindJSON(&svc); err != nil {
  107. appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
  108. return
  109. }
  110. if err := svc.Delete(); err != nil {
  111. appG.Response(http.StatusOK, e.ERROR, err.Error())
  112. return
  113. }
  114. appG.Response(http.StatusOK, e.SUCCESS, nil)
  115. }