Skip to content

Commit

Permalink
Add Aliance Station Status API
Browse files Browse the repository at this point in the history
  • Loading branch information
cpapplefamily committed Nov 30, 2024
1 parent d80c26c commit 8224cdc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions web/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"os"
"strconv"
"log"

)

type MatchResultWithSummary struct {
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8224cdc

Please sign in to comment.