diff --git a/web/api.go b/web/api.go index cb6e7378..6cf4c0e0 100644 --- a/web/api.go +++ b/web/api.go @@ -18,6 +18,7 @@ import ( "os" "strconv" "log" + ) type MatchResultWithSummary struct { @@ -179,6 +180,31 @@ func (web *Web) rankingsApiHandler(w http.ResponseWriter, r *http.Request) { } } + +// Generates a JSON dump of the arenaStatus, primarily for use by the stack Lights. +func (web *Web) allianceStatusApiHandler(w http.ResponseWriter, r *http.Request) { + // Preload the JSON as a string + var allianceStations = web.arena.AllianceStations + + // Iterate through the slice of AllianceStation structs + for i := range allianceStations { + // If the struct has a Team field, remove or clear it + allianceStations[i].Team = nil // Remove Team information + } + jsonData, err := json.Marshal(allianceStations) + if err != nil { + handleWebErr(w, err) + return + } + + w.Header().Set("Content-Type", "application/json") + _, err = w.Write(jsonData) + if err != nil { + handleWebErr(w, err) + return + } +} + // Generates a JSON dump of the alliances. func (web *Web) alliancesApiHandler(w http.ResponseWriter, r *http.Request) { alliances, err := web.arena.Database.GetAllAlliances() diff --git a/web/web.go b/web/web.go index 05a00945..393662ef 100644 --- a/web/web.go +++ b/web/web.go @@ -136,6 +136,7 @@ func (web *Web) newHandler() http.Handler { mux.HandleFunc("GET /api/bracket/svg", web.bracketSvgApiHandler) mux.HandleFunc("GET /api/matches/{type}", web.matchesApiHandler) mux.HandleFunc("GET /api/rankings", web.rankingsApiHandler) + mux.HandleFunc("GET /api/allianceStatus", web.allianceStatusApiHandler) mux.HandleFunc("GET /api/sponsor_slides", web.sponsorSlidesApiHandler) mux.HandleFunc("GET /api/teams/{teamId}/avatar", web.teamAvatarsApiHandler) mux.HandleFunc("GET /display", web.placeholderDisplayHandler)