feat: gamemaster

This commit is contained in:
Ilia Denisov
2026-05-03 07:59:03 +02:00
committed by GitHub
parent a7cee15115
commit 3e2622757e
229 changed files with 41521 additions and 1098 deletions
@@ -0,0 +1,67 @@
package handlers
import (
"net/http"
"strconv"
"strings"
"galaxy/gamemaster/internal/domain/operation"
"galaxy/gamemaster/internal/service/reportget"
)
// newGetReportHandler returns the handler for
// `GET /api/v1/internal/games/{game_id}/reports/{turn}`. Path
// validation rejects non-numeric or negative turn values with
// `400 invalid_request` before the service is touched.
func newGetReportHandler(deps Dependencies) http.HandlerFunc {
logger := loggerFor(deps.Logger, "internal_rest.get_report")
return func(writer http.ResponseWriter, request *http.Request) {
if deps.GetReport == nil {
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "get report service is not wired")
return
}
gameID, ok := extractGameID(writer, request)
if !ok {
return
}
userID, ok := extractUserID(writer, request)
if !ok {
return
}
raw := strings.TrimSpace(request.PathValue(turnPathParam))
if raw == "" {
writeError(writer, http.StatusBadRequest, errorCodeInvalidRequest, "turn is required")
return
}
turn, err := strconv.Atoi(raw)
if err != nil || turn < 0 {
writeError(writer, http.StatusBadRequest, errorCodeInvalidRequest, "turn must be a non-negative integer")
return
}
result, err := deps.GetReport.Handle(request.Context(), reportget.Input{
GameID: gameID,
UserID: userID,
Turn: turn,
})
if err != nil {
logger.ErrorContext(request.Context(), "get report service errored",
"game_id", gameID,
"user_id", userID,
"turn", turn,
"err", err.Error(),
)
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "get report service failed")
return
}
if result.Outcome == operation.OutcomeFailure {
writeFailure(writer, result.ErrorCode, result.ErrorMessage)
return
}
writeRawJSON(writer, http.StatusOK, []byte(result.RawResponse))
}
}