feat: game lobby service

This commit is contained in:
Ilia Denisov
2026-04-25 23:20:55 +02:00
committed by GitHub
parent 32dc29359a
commit 48b0056b49
336 changed files with 57074 additions and 1418 deletions
@@ -0,0 +1,54 @@
package publichttp
import (
"log/slog"
"net/http"
"galaxy/lobby/internal/service/manualreadytostart"
)
const readyToStartPath = "/api/v1/lobby/games/{game_id}/ready-to-start"
// registerReadyToStartRoutes binds the manual ready-to-start route
// on the public port. The route requires the X-User-ID header so the actor
// is always a user; admins use the internal port.
func registerReadyToStartRoutes(mux *http.ServeMux, deps Dependencies, logger *slog.Logger) {
h := &readyToStartHandlers{
deps: deps,
logger: logger.With("component", "public_http.ready_to_start"),
}
mux.HandleFunc("POST "+readyToStartPath, h.handle)
}
type readyToStartHandlers struct {
deps Dependencies
logger *slog.Logger
}
func (h *readyToStartHandlers) handle(writer http.ResponseWriter, request *http.Request) {
if h.deps.ManualReadyToStart == nil {
writeError(writer, http.StatusInternalServerError, "internal_error", "manual ready-to-start service is not wired")
return
}
games := &gameHandlers{deps: h.deps, logger: h.logger}
actor, ok := games.requireUserActor(writer, request)
if !ok {
return
}
gameID, ok := games.extractGameID(writer, request)
if !ok {
return
}
record, err := h.deps.ManualReadyToStart.Handle(request.Context(), manualreadytostart.Input{
Actor: actor,
GameID: gameID,
})
if err != nil {
writeErrorFromService(writer, h.logger, err)
return
}
writeJSON(writer, http.StatusOK, encodeGameRecord(record))
}