| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package newCentralControl
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "log-server/global"
- "log-server/model/common/request"
- "log-server/model/common/response"
- "log-server/model/newCentralControl"
- newCentralControlRequest "log-server/model/newCentralControl/request"
- "log-server/utils"
- )
- type GameConfApi struct {
- }
- //创建游戏配置
- func (a *GameConfApi) CreateGameConf (c *gin.Context) {
- var conf newCentralControl.GameConf
- _ = c.ShouldBindJSON(&conf)
- if conf.Mirror == "" {
- response.FailWithMessage("请传入镜像名称", c)
- return
- }
- if conf.Script == "" {
- response.FailWithMessage("请传入脚本名称", c)
- return
- }
- if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := gameConfService.CreateGameConf(conf);err != nil {
- global.GVA_LOG.Error("创建失败!", zap.Error(err))
- response.FailWithMessage("创建失败", c)
- } else {
- response.OkWithMessage("创建成功", c)
- }
- }
- //删除游戏配置
- func (a *GameConfApi) DeleteGameConf(c *gin.Context) {
- var conf newCentralControl.GameConf
- _ = c.ShouldBindJSON(&conf)
- //数据校验
- if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := gameConfService.DeleteGameConf(conf); err != nil{
- global.GVA_LOG.Error("删除失败!", zap.Error(err))
- response.FailWithMessage("删除失败", c)
- } else {
- response.OkWithMessage("删除成功", c)
- }
- }
- //编辑游戏配置
- func (a *GameConfApi) UpdateGameConf(c *gin.Context) {
- var conf newCentralControl.GameConf
- _ = c.ShouldBindJSON(&conf)
- //数据校验
- fmt.Println(conf)
- if err := utils.Verify(conf, utils.GameConfVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if err := gameConfService.UpdateGameConf(conf); err != nil {
- global.GVA_LOG.Error("更新失败!", zap.Error(err))
- response.FailWithMessage("更新失败", c)
- } else {
- response.OkWithMessage("更新成功", c)
- }
- }
- //id获取游戏配置
- func (a *GameConfApi) GetGameConfById(c *gin.Context) {
- var id request.GetById
- _ = c.ShouldBindJSON(&id)
- if err := utils.Verify(id, utils.IdVerify); err != nil {
- response.FailWithMessage(err.Error(), c)
- return
- }
- if conf,err := gameConfService.GetGameConfById(id.ID); err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- }else {
- response.OkWithDetailed(conf, "获取成功", c)
- }
- }
- //获取游戏配置列表
- func (a *GameConfApi) GetGameConfList(c *gin.Context) {
- var pageInfo newCentralControlRequest.SearchGameConfParams
- _ = c.ShouldBindJSON(&pageInfo)
- //页面信息校验
- if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil{
- response.FailWithMessage(err.Error(), c)
- return
- }
- if list, total, err := gameConfService.GetGameConfList(pageInfo.GameConf, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
- global.GVA_LOG.Error("获取失败!", zap.Error(err))
- response.FailWithMessage("获取失败", c)
- } else {
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: pageInfo.Page,
- PageSize: pageInfo.PageSize,
- }, "获取成功", c)
- }
- }
|