feat: init api
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package handler
|
||||
|
||||
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.Config) {
|
||||
var init rest.Init
|
||||
if err := c.ShouldBindJSON(&init); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
races := make([]string, len(init.Races))
|
||||
for i := range init.Races {
|
||||
races[i] = init.Races[i].Name
|
||||
}
|
||||
|
||||
uuid, err := game.GenerateGame(config, races)
|
||||
if transformError(c, err) {
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
c.JSON(http.StatusCreated, rest.InitResponse{
|
||||
UUID: uuid,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user