55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
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))
|
|
}
|