27 lines
492 B
Go
27 lines
492 B
Go
package rest_handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gitea.elara.ws/Hazel/hangman/internal/game"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func CreateUser(c echo.Context) error {
|
|
session := game.GetSession(c.Param("session"))
|
|
|
|
type BodyContent struct {
|
|
Name string
|
|
}
|
|
var bodyContent BodyContent
|
|
|
|
err := c.Bind(&bodyContent)
|
|
if err != nil {
|
|
return c.String(http.StatusBadRequest, err.Error())
|
|
}
|
|
|
|
user := game.NewUser(bodyContent.Name)
|
|
session.AddUser(user)
|
|
return c.JSON(http.StatusOK, user)
|
|
}
|