feat: game lobby service
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package internalhttp
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"galaxy/lobby/internal/service/manualreadytostart"
|
||||
"galaxy/lobby/internal/service/shared"
|
||||
)
|
||||
|
||||
const readyToStartPath = "/api/v1/lobby/games/{game_id}/ready-to-start"
|
||||
|
||||
// registerReadyToStartRoutes binds the admin manual ready-to-start
|
||||
// route on the internal port. The actor is always admin (Admin Service is
|
||||
// the trusted caller; the internal port is not reachable from the public
|
||||
// internet).
|
||||
func registerReadyToStartRoutes(mux *http.ServeMux, deps Dependencies, logger *slog.Logger) {
|
||||
h := &readyToStartHandlers{
|
||||
deps: deps,
|
||||
logger: logger.With("component", "internal_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}
|
||||
gameID, ok := games.extractGameID(writer, request)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
record, err := h.deps.ManualReadyToStart.Handle(request.Context(), manualreadytostart.Input{
|
||||
Actor: shared.NewAdminActor(),
|
||||
GameID: gameID,
|
||||
})
|
||||
if err != nil {
|
||||
writeErrorFromService(writer, h.logger, err)
|
||||
return
|
||||
}
|
||||
|
||||
writeJSON(writer, http.StatusOK, encodeGameRecord(record))
|
||||
}
|
||||
Reference in New Issue
Block a user