feat: creation of new user

This commit is contained in:
Hazel Noack
2025-06-27 10:44:24 +02:00
parent 9ded6a4615
commit 64fa44e45e
5 changed files with 59 additions and 15 deletions

View File

@@ -3,11 +3,11 @@ package rest_handler
import (
"net/http"
"gitea.elara.ws/Hazel/hangman/internal/session"
"gitea.elara.ws/Hazel/hangman/internal/game"
"github.com/labstack/echo/v4"
)
func CreateSession(c echo.Context) error {
s := session.NewSession()
s := game.NewSession()
return c.JSON(http.StatusOK, s)
}

View File

@@ -0,0 +1,26 @@
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)
}