game_conf.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package newCentralControl
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "go.uber.org/zap"
  6. "log-server/global"
  7. "log-server/model/common/request"
  8. "log-server/model/common/response"
  9. "log-server/model/newCentralControl"
  10. newCentralControlRequest "log-server/model/newCentralControl/request"
  11. "log-server/utils"
  12. )
  13. type GameConfApi struct {
  14. }
  15. //创建游戏配置
  16. func (a *GameConfApi) CreateGameConf (c *gin.Context) {
  17. var conf newCentralControl.GameConf
  18. _ = c.ShouldBindJSON(&conf)
  19. if conf.Mirror == "" {
  20. response.FailWithMessage("请传入镜像名称", c)
  21. return
  22. }
  23. if conf.Script == "" {
  24. response.FailWithMessage("请传入脚本名称", c)
  25. return
  26. }
  27. if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
  28. response.FailWithMessage(err.Error(), c)
  29. return
  30. }
  31. if err := gameConfService.CreateGameConf(conf);err != nil {
  32. global.GVA_LOG.Error("创建失败!", zap.Error(err))
  33. response.FailWithMessage("创建失败", c)
  34. } else {
  35. response.OkWithMessage("创建成功", c)
  36. }
  37. }
  38. //删除游戏配置
  39. func (a *GameConfApi) DeleteGameConf(c *gin.Context) {
  40. var conf newCentralControl.GameConf
  41. _ = c.ShouldBindJSON(&conf)
  42. //数据校验
  43. if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
  44. response.FailWithMessage(err.Error(), c)
  45. return
  46. }
  47. if err := gameConfService.DeleteGameConf(conf); err != nil{
  48. global.GVA_LOG.Error("删除失败!", zap.Error(err))
  49. response.FailWithMessage("删除失败", c)
  50. } else {
  51. response.OkWithMessage("删除成功", c)
  52. }
  53. }
  54. //编辑游戏配置
  55. func (a *GameConfApi) UpdateGameConf(c *gin.Context) {
  56. var conf newCentralControl.GameConf
  57. _ = c.ShouldBindJSON(&conf)
  58. //数据校验
  59. fmt.Println(conf)
  60. if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
  61. response.FailWithMessage(err.Error(), c)
  62. return
  63. }
  64. if err := gameConfService.UpdateGameConf(conf); err != nil {
  65. global.GVA_LOG.Error("更新失败!", zap.Error(err))
  66. response.FailWithMessage("更新失败", c)
  67. } else {
  68. response.OkWithMessage("更新成功", c)
  69. }
  70. }
  71. //id获取游戏配置
  72. func (a *GameConfApi) GetGameConfById(c *gin.Context) {
  73. var id request.GetById
  74. _ = c.ShouldBindJSON(&id)
  75. if err := utils.Verify(id, utils.IdVerify); err != nil {
  76. response.FailWithMessage(err.Error(), c)
  77. return
  78. }
  79. if conf,err := gameConfService.GetGameConfById(id.ID); err != nil {
  80. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  81. response.FailWithMessage("获取失败", c)
  82. }else {
  83. response.OkWithDetailed(conf, "获取成功", c)
  84. }
  85. }
  86. //获取游戏配置列表
  87. func (a *GameConfApi) GetGameConfList(c *gin.Context) {
  88. var pageInfo newCentralControlRequest.SearchGameConfParams
  89. _ = c.ShouldBindJSON(&pageInfo)
  90. //页面信息校验
  91. if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil{
  92. response.FailWithMessage(err.Error(), c)
  93. return
  94. }
  95. if list, total, err := gameConfService.GetGameConfList(pageInfo.GameConf, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
  96. global.GVA_LOG.Error("获取失败!", zap.Error(err))
  97. response.FailWithMessage("获取失败", c)
  98. } else {
  99. response.OkWithDetailed(response.PageResult{
  100. List: list,
  101. Total: total,
  102. Page: pageInfo.Page,
  103. PageSize: pageInfo.PageSize,
  104. }, "获取成功", c)
  105. }
  106. }