/*
* This file is part of sdbapi
* Copyright (C) 2023 Jonni Liljamo <jonni@liljamo.com>
*
* Licensed under GPL-3.0-only.
* See LICENSE for licensing information.
*/
package handlers
import (
"api/apierror"
"api/db"
"api/models"
"net/http"
"github.com/gin-gonic/gin"
)
func CreateGame(c *gin.Context) {
host, _ := db.GetUserByEmail(c.GetString("email"))
var game models.Game
game.HostID = host.ID
game.State = models.GAMESTATE_FORMING
entry := db.DbConn.Create(&game)
if entry.Error != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": apierror.GameCreationFailed})
c.Abort()
return
}
c.JSON(http.StatusCreated, game)
}