28 lines
488 B
Go
28 lines
488 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/iliadenisov/galaxy/internal/model/rest"
|
|
)
|
|
|
|
func InitHandler(c *gin.Context, executor CommandExecutor) {
|
|
var init rest.Init
|
|
if errorResponded(c, c.ShouldBindJSON(&init)) {
|
|
return
|
|
}
|
|
|
|
races := make([]string, len(init.Races))
|
|
for i := range init.Races {
|
|
races[i] = init.Races[i].Name
|
|
}
|
|
|
|
s, err := executor.GenerateGame(races)
|
|
if errorResponded(c, err) {
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, s)
|
|
}
|