mchess-server/handler/handler.go

35 lines
723 B
Go

package handler
import (
"mchess_server/api"
lobbies "mchess_server/lobby_registry"
"mchess_server/utils"
"net/http"
"github.com/gin-gonic/gin"
)
func GetLobbyFromPassphraseHandler(c *gin.Context) {
reqPassphrase := api.Passphrase{}
err := c.ShouldBindJSON(&reqPassphrase)
if err != nil || reqPassphrase.Value == nil || *reqPassphrase.Value == "" {
c.IndentedJSON(http.StatusNotFound, reqPassphrase)
return
}
lobby := lobbies.GetLobbyRegistry().GetLobbyByPassphrase(
utils.NewPassphraseFromString(*reqPassphrase.Value))
if lobby == nil {
c.IndentedJSON(http.StatusNotFound, reqPassphrase)
return
}
lobbyInfo := api.LobbyInfo{
ID: &lobby.Uuid,
}
c.IndentedJSON(http.StatusOK, lobbyInfo)
}