mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 00:14:00 +00:00
feat: make proposal responses durable
This commit is contained in:
+21
-8
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user