feat: make proposal responses durable

This commit is contained in:
Josh Creek
2026-09-01 07:52:52 +01:00
parent 30b4560bd5
commit eef7cf28da
6 changed files with 228 additions and 16 deletions
+21 -8
View File
@@ -45,6 +45,9 @@ type SessionIssuer interface {
type ProposalBackend interface {
Get(context.Context, string, string, time.Time) (domain.Proposal, error)
}
type ProposalMutationBackend interface {
Respond(context.Context, string, string, string, bool, uint64, time.Time) (domain.Proposal, error)
}
type AssignmentView struct {
MatchID string `json:"match_id"`
@@ -451,15 +454,25 @@ func (s *Service) proposalMutation(w http.ResponseWriter, r *http.Request) {
writeError(w, http.StatusBadRequest, "invalid_revision")
return
}
s.proposalMu.Lock()
defer s.proposalMu.Unlock()
proposal, exists := s.Proposals[parts[0]]
if !exists || proposal == nil {
writeError(w, http.StatusNotFound, "not_found")
return
}
now := s.now()
updated, err := proposal.Respond(playerID, key, parts[1] == "accept", revision, now)
var updated domain.Proposal
if s.ProposalBackend != nil {
mutator, supportsMutation := s.ProposalBackend.(ProposalMutationBackend)
if !supportsMutation {
writeError(w, http.StatusServiceUnavailable, "proposal_unavailable")
return
}
updated, err = mutator.Respond(r.Context(), playerID, parts[0], key, parts[1] == "accept", revision, now)
} else {
s.proposalMu.Lock()
defer s.proposalMu.Unlock()
proposal, exists := s.Proposals[parts[0]]
if !exists || proposal == nil {
writeError(w, http.StatusNotFound, "not_found")
return
}
updated, err = proposal.Respond(playerID, key, parts[1] == "accept", revision, now)
}
if err != nil {
writeDomainError(w, err)
return