feat: creation of new user
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
26
internal/rest_handler/create_user.go
Normal file
26
internal/rest_handler/create_user.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user