mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-10 06:06:47 -04:00
Add score summaries to matches API.
This commit is contained in:
16
api.go
16
api.go
@@ -11,9 +11,15 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type MatchResultWithSummary struct {
|
||||
MatchResult
|
||||
RedSummary *ScoreSummary
|
||||
BlueSummary *ScoreSummary
|
||||
}
|
||||
|
||||
type MatchWithResult struct {
|
||||
Match
|
||||
Result *MatchResult
|
||||
Result *MatchResultWithSummary
|
||||
}
|
||||
|
||||
type RankingWithNickname struct {
|
||||
@@ -42,7 +48,13 @@ func MatchesApiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
matchesWithResults[i].Result = matchResult
|
||||
var matchResultWithSummary *MatchResultWithSummary
|
||||
if matchResult != nil {
|
||||
matchResultWithSummary = &MatchResultWithSummary{MatchResult: *matchResult}
|
||||
matchResultWithSummary.RedSummary = matchResult.RedScoreSummary()
|
||||
matchResultWithSummary.BlueSummary = matchResult.BlueScoreSummary()
|
||||
}
|
||||
matchesWithResults[i].Result = matchResultWithSummary
|
||||
}
|
||||
|
||||
jsonData, err := json.MarshalIndent(matchesWithResults, "", " ")
|
||||
|
||||
@@ -34,7 +34,7 @@ func TestMatchesApi(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
if assert.Equal(t, 2, len(matchesData)) {
|
||||
assert.Equal(t, match1.Id, matchesData[0].Match.Id)
|
||||
assert.Equal(t, matchResult1, *(matchesData[0].Result))
|
||||
assert.Equal(t, matchResult1, matchesData[0].Result.MatchResult)
|
||||
assert.Equal(t, match2.Id, matchesData[1].Match.Id)
|
||||
assert.Nil(t, matchesData[1].Result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user