116 lines
3.2 KiB
Go
116 lines
3.2 KiB
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"chatapp3-golang/internal/common"
|
|
"chatapp3-golang/internal/service/hotgame"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// registerHotgameRoutes 注册热游后台管理类 Go 接口。
|
|
func registerHotgameRoutes(engine *gin.Engine, javaClient authGateway, service *hotgame.Service) {
|
|
if service == nil {
|
|
return
|
|
}
|
|
consoleGroup := engine.Group("/operate/hotgame-game")
|
|
consoleGroup.Use(consoleAuthMiddleware(javaClient))
|
|
consoleGroup.GET("/config", func(c *gin.Context) {
|
|
resp, err := service.GetProviderConfig(c.Request.Context(), c.Query("sysOrigin"), c.Query("profile"))
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.POST("/config", func(c *gin.Context) {
|
|
var req hotgame.SaveProviderConfigRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, common.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.SaveProviderConfig(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.POST("/config/activate", func(c *gin.Context) {
|
|
var req hotgame.ActivateProviderProfileRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, common.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.ActivateProviderProfile(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.GET("/catalog/page", func(c *gin.Context) {
|
|
cursor, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("cursor", "1")))
|
|
limit, _ := strconv.Atoi(strings.TrimSpace(c.DefaultQuery("limit", "20")))
|
|
resp, err := service.PageCatalog(
|
|
c.Request.Context(),
|
|
c.Query("sysOrigin"),
|
|
c.Query("profile"),
|
|
c.Query("keyword"),
|
|
cursor,
|
|
limit,
|
|
)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.POST("/catalog/fetch", func(c *gin.Context) {
|
|
var req hotgame.SyncCatalogRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, common.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.FetchAdminCatalog(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.POST("/import-catalog", func(c *gin.Context) {
|
|
var req hotgame.SyncCatalogRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, common.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
defaultShowcase := true
|
|
if req.DefaultShowcase != nil {
|
|
defaultShowcase = *req.DefaultShowcase
|
|
}
|
|
resp, err := service.ImportCatalogGames(c.Request.Context(), req.SysOrigin, req.Profile, req.VendorGameIDs, defaultShowcase)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
consoleGroup.POST("/sync", func(c *gin.Context) {
|
|
var req hotgame.SyncCatalogRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
writeError(c, common.NewAppError(http.StatusBadRequest, "bad_request", err.Error()))
|
|
return
|
|
}
|
|
resp, err := service.SyncAdminGames(c.Request.Context(), req)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
writeOK(c, resp)
|
|
})
|
|
}
|