mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat: wire durable assignments into API
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/store"
|
||||
)
|
||||
|
||||
// AssignmentProviderFromStore adapts the durable player-scoped assignment
|
||||
// projection to the HTTP boundary. The store query filters expiry and binds
|
||||
// both match and player; the API still performs its response-shape checks.
|
||||
func AssignmentProviderFromStore(db *sql.DB) AssignmentProvider {
|
||||
return func(ctx context.Context, playerID, matchID string, now time.Time) (AssignmentView, error) {
|
||||
assignment, err := store.GetAssignment(ctx, db, playerID, matchID, now)
|
||||
if err != nil {
|
||||
return AssignmentView{}, err
|
||||
}
|
||||
return AssignmentView{
|
||||
MatchID: assignment.MatchID,
|
||||
ServerID: assignment.ServerID,
|
||||
PlayerID: assignment.PlayerID,
|
||||
Slot: assignment.Slot,
|
||||
ExpiresAt: assignment.ExpiresAt,
|
||||
ProtocolVersion: assignment.ProtocolVersion,
|
||||
Transport: assignment.Transport,
|
||||
JoinAuthorisation: assignment.JoinAuthorisation,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAssignmentProviderFromStorePreservesPlayerScopedRecoveryBoundary(t *testing.T) {
|
||||
provider := AssignmentProviderFromStore(nil)
|
||||
if provider == nil {
|
||||
t.Fatal("store provider was not created")
|
||||
}
|
||||
if _, err := provider(context.Background(), "player-1", "match-1", time.Unix(1000, 0)); err == nil {
|
||||
t.Fatal("nil store was treated as an available assignment source")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user