refactor: executors and routers
* refactor: executors and routers
This commit is contained in:
@@ -4,15 +4,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/iliadenisov/galaxy/internal/controller"
|
||||
"github.com/iliadenisov/galaxy/internal/game"
|
||||
"github.com/iliadenisov/galaxy/internal/model/rest"
|
||||
)
|
||||
|
||||
func InitHandler(c *gin.Context, config controller.Configurer) {
|
||||
func InitHandler(c *gin.Context, executor CommandExecutor) {
|
||||
var init rest.Init
|
||||
if err := c.ShouldBindJSON(&init); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
if errorResponded(c, c.ShouldBindJSON(&init)) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -21,10 +18,9 @@ func InitHandler(c *gin.Context, config controller.Configurer) {
|
||||
races[i] = init.Races[i].Name
|
||||
}
|
||||
|
||||
uuid, err := game.GenerateGame(config, races)
|
||||
if transformError(c, err) {
|
||||
uuid, err := executor.GenerateGame(races)
|
||||
if errorResponded(c, err) {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, rest.InitResponse{
|
||||
|
||||
Reference in New Issue
Block a user