ebd156ece2
Tests · UI / test (push) Has been cancelled
Tests · Go / test (pull_request) Successful in 2m6s
Tests · Go / test (push) Successful in 2m7s
Tests · Integration / integration (pull_request) Successful in 1m47s
Tests · UI / test (pull_request) Failing after 3m42s
The Phase 27 BattleViewer was the last UI surface still issuing raw
fetch() against the backend REST contract (`/api/v1/user/games/...
/battles/...`). The dev-deploy gateway never proxied that path, so
the viewer worked only in tools/local-dev/. Move it onto the signed
ConnectRPC channel every other authenticated surface already uses.
Wire pieces:
- FBS GameBattleRequest in pkg/schema/fbs/battle.fbs, regenerated
Go + TS bindings.
- MessageTypeUserGamesBattle constant + GameBattleRequest struct in
pkg/model/report/messages.go.
- pkg/transcoder/battle.go gains GameBattleRequestToPayload and
PayloadToGameBattleRequest helpers.
- gateway games_commands.go switches on the new message type and
GETs /api/v1/user/games/{id}/battles/{turn}/{battle_id}; the JSON
response is re-encoded as a FlatBuffers BattleReport before being
returned. 404 from backend surfaces as the canonical `not_found`
gateway error.
- ui/frontend/src/api/battle-fetch.ts now builds the FBS request,
calls GalaxyClient.executeCommand, and decodes the FBS response
into the existing UI shape (Record<string,string> race/ship maps,
string-form UUID). BattleFetchError carries an HTTP-style status
derived from the result code so the active-view's not_found branch
keeps working.
- battle.svelte pulls the GalaxyClient from the in-game shell
context. While the layout's boot Promise.all is in flight the
effect stays in `loading` until the client handle becomes
non-null.
- ui/Makefile FBS_INPUTS gains battle.fbs.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
138 lines
4.9 KiB
Go
138 lines
4.9 KiB
Go
package backendclient
|
|
|
|
import (
|
|
"context"
|
|
|
|
"galaxy/gateway/internal/downstream"
|
|
diplomailmodel "galaxy/model/diplomail"
|
|
lobbymodel "galaxy/model/lobby"
|
|
ordermodel "galaxy/model/order"
|
|
reportmodel "galaxy/model/report"
|
|
usermodel "galaxy/model/user"
|
|
)
|
|
|
|
// UserRoutes returns the authenticated `user.*` downstream routes
|
|
// served by backend. When client is nil every route resolves to a
|
|
// dependency-unavailable client so the static router still recognises
|
|
// the message types.
|
|
func UserRoutes(client *RESTClient) map[string]downstream.Client {
|
|
target := downstream.Client(unavailableClient{})
|
|
if client != nil {
|
|
target = userCommandClient{rest: client}
|
|
}
|
|
return map[string]downstream.Client{
|
|
usermodel.MessageTypeGetMyAccount: target,
|
|
usermodel.MessageTypeUpdateMyProfile: target,
|
|
usermodel.MessageTypeUpdateMySettings: target,
|
|
usermodel.MessageTypeListMySessions: target,
|
|
usermodel.MessageTypeRevokeMySession: target,
|
|
usermodel.MessageTypeRevokeAllMySessions: target,
|
|
}
|
|
}
|
|
|
|
// LobbyRoutes returns the authenticated `lobby.*` downstream routes
|
|
// served by backend. When client is nil every route resolves to a
|
|
// dependency-unavailable client.
|
|
func LobbyRoutes(client *RESTClient) map[string]downstream.Client {
|
|
target := downstream.Client(unavailableClient{})
|
|
if client != nil {
|
|
target = lobbyCommandClient{rest: client}
|
|
}
|
|
return map[string]downstream.Client{
|
|
lobbymodel.MessageTypeMyGamesList: target,
|
|
lobbymodel.MessageTypePublicGamesList: target,
|
|
lobbymodel.MessageTypeMyApplicationsList: target,
|
|
lobbymodel.MessageTypeMyInvitesList: target,
|
|
lobbymodel.MessageTypeOpenEnrollment: target,
|
|
lobbymodel.MessageTypeGameCreate: target,
|
|
lobbymodel.MessageTypeApplicationSubmit: target,
|
|
lobbymodel.MessageTypeInviteRedeem: target,
|
|
lobbymodel.MessageTypeInviteDecline: target,
|
|
}
|
|
}
|
|
|
|
// GameRoutes returns the authenticated `user.games.*` downstream
|
|
// routes served by backend (which in turn forwards to the running
|
|
// game engine container). When client is nil every route resolves to
|
|
// a dependency-unavailable client.
|
|
func GameRoutes(client *RESTClient) map[string]downstream.Client {
|
|
target := downstream.Client(unavailableClient{})
|
|
if client != nil {
|
|
target = gameCommandClient{rest: client}
|
|
}
|
|
return map[string]downstream.Client{
|
|
ordermodel.MessageTypeUserGamesCommand: target,
|
|
ordermodel.MessageTypeUserGamesOrder: target,
|
|
ordermodel.MessageTypeUserGamesOrderGet: target,
|
|
reportmodel.MessageTypeUserGamesReport: target,
|
|
reportmodel.MessageTypeUserGamesBattle: target,
|
|
}
|
|
}
|
|
|
|
// MailRoutes returns the authenticated `user.games.mail.*` downstream
|
|
// routes served by backend's diplomail subsystem. When client is nil
|
|
// every route resolves to a dependency-unavailable client so the
|
|
// static router still recognises the message types.
|
|
func MailRoutes(client *RESTClient) map[string]downstream.Client {
|
|
target := downstream.Client(unavailableClient{})
|
|
if client != nil {
|
|
target = mailCommandClient{rest: client}
|
|
}
|
|
return map[string]downstream.Client{
|
|
diplomailmodel.MessageTypeUserGamesMailInbox: target,
|
|
diplomailmodel.MessageTypeUserGamesMailSent: target,
|
|
diplomailmodel.MessageTypeUserGamesMailMessageGet: target,
|
|
diplomailmodel.MessageTypeUserGamesMailSend: target,
|
|
diplomailmodel.MessageTypeUserGamesMailBroadcast: target,
|
|
diplomailmodel.MessageTypeUserGamesMailAdmin: target,
|
|
diplomailmodel.MessageTypeUserGamesMailRead: target,
|
|
diplomailmodel.MessageTypeUserGamesMailDelete: target,
|
|
}
|
|
}
|
|
|
|
type unavailableClient struct{}
|
|
|
|
func (unavailableClient) ExecuteCommand(context.Context, downstream.AuthenticatedCommand) (downstream.UnaryResult, error) {
|
|
return downstream.UnaryResult{}, downstream.ErrDownstreamUnavailable
|
|
}
|
|
|
|
type userCommandClient struct {
|
|
rest *RESTClient
|
|
}
|
|
|
|
func (c userCommandClient) ExecuteCommand(ctx context.Context, command downstream.AuthenticatedCommand) (downstream.UnaryResult, error) {
|
|
return c.rest.ExecuteUserCommand(ctx, command)
|
|
}
|
|
|
|
type lobbyCommandClient struct {
|
|
rest *RESTClient
|
|
}
|
|
|
|
func (c lobbyCommandClient) ExecuteCommand(ctx context.Context, command downstream.AuthenticatedCommand) (downstream.UnaryResult, error) {
|
|
return c.rest.ExecuteLobbyCommand(ctx, command)
|
|
}
|
|
|
|
type gameCommandClient struct {
|
|
rest *RESTClient
|
|
}
|
|
|
|
func (c gameCommandClient) ExecuteCommand(ctx context.Context, command downstream.AuthenticatedCommand) (downstream.UnaryResult, error) {
|
|
return c.rest.ExecuteGameCommand(ctx, command)
|
|
}
|
|
|
|
type mailCommandClient struct {
|
|
rest *RESTClient
|
|
}
|
|
|
|
func (c mailCommandClient) ExecuteCommand(ctx context.Context, command downstream.AuthenticatedCommand) (downstream.UnaryResult, error) {
|
|
return c.rest.ExecuteMailCommand(ctx, command)
|
|
}
|
|
|
|
var (
|
|
_ downstream.Client = unavailableClient{}
|
|
_ downstream.Client = userCommandClient{}
|
|
_ downstream.Client = lobbyCommandClient{}
|
|
_ downstream.Client = gameCommandClient{}
|
|
_ downstream.Client = mailCommandClient{}
|
|
)
|