feat: load player's report
This commit is contained in:
@@ -11,19 +11,19 @@ import (
|
||||
"github.com/iliadenisov/galaxy/internal/model/rest"
|
||||
)
|
||||
|
||||
type CommandExecutor func(controller.Config, rest.Command) error
|
||||
type CommandExecutor func(controller.Configurer, rest.Command) error
|
||||
|
||||
var (
|
||||
ErrCommandNotProcessed = errors.New("command was not processed by executor")
|
||||
)
|
||||
|
||||
func CommandHandler(c *gin.Context, config controller.Config, executor CommandExecutor) {
|
||||
func CommandHandler(c *gin.Context, configurer controller.Configurer, executor CommandExecutor) {
|
||||
var cmd rest.Command
|
||||
if err := c.ShouldBindJSON(&cmd); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
err := executor(config, cmd)
|
||||
err := executor(configurer, cmd)
|
||||
switch {
|
||||
case err == nil:
|
||||
c.Status(http.StatusOK)
|
||||
@@ -35,7 +35,7 @@ func CommandHandler(c *gin.Context, config controller.Config, executor CommandEx
|
||||
}
|
||||
}
|
||||
|
||||
func ExecuteCommand(config controller.Config, cmd rest.Command) error {
|
||||
func ExecuteCommand(config controller.Configurer, cmd rest.Command) error {
|
||||
switch {
|
||||
case cmd.DeclareWar != nil:
|
||||
return game.DeclareWar(config, cmd.Race, cmd.DeclareWar.Opponent)
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/iliadenisov/galaxy/internal/model/rest"
|
||||
)
|
||||
|
||||
func InitHandler(c *gin.Context, config controller.Config) {
|
||||
func InitHandler(c *gin.Context, config controller.Configurer) {
|
||||
var init rest.Init
|
||||
if err := c.ShouldBindJSON(&init); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/iliadenisov/galaxy/internal/model/rest"
|
||||
)
|
||||
|
||||
func StatusHandler(c *gin.Context, config controller.Config) {
|
||||
func StatusHandler(c *gin.Context, config controller.Configurer) {
|
||||
g, err := game.LoadState(config)
|
||||
|
||||
if transformError(c, err) {
|
||||
|
||||
@@ -18,7 +18,6 @@ const (
|
||||
|
||||
func initConfig() func(*controller.Param) {
|
||||
return func(p *controller.Param) {
|
||||
// TODO: initialize base controller settings
|
||||
p.StoragePath = os.Getenv("STORAGE_PATH")
|
||||
}
|
||||
}
|
||||
@@ -40,7 +39,7 @@ func NewRouterExecutor(executor handler.CommandExecutor) Router {
|
||||
return Router{r: setupRouter(initConfig(), executor)}
|
||||
}
|
||||
|
||||
func setupRouter(config controller.Config, executor handler.CommandExecutor) *gin.Engine {
|
||||
func setupRouter(config controller.Configurer, executor handler.CommandExecutor) *gin.Engine {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
r := gin.New()
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ func SetupRouter() *gin.Engine {
|
||||
return SetupRouterConfig(nil)
|
||||
}
|
||||
|
||||
func SetupRouterConfig(config controller.Config) *gin.Engine {
|
||||
return setupRouter(config, func(controller.Config, rest.Command) error { return nil })
|
||||
func SetupRouterConfig(config controller.Configurer) *gin.Engine {
|
||||
return setupRouter(config, func(controller.Configurer, rest.Command) error { return nil })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user