mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Add JSON Rankings
This commit is contained in:
24
reports.go
24
reports.go
@@ -12,6 +12,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"text/template"
|
||||
"io"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Generates a CSV-formatted report of the qualification rankings.
|
||||
@@ -36,6 +38,28 @@ func RankingsCsvReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a JSON-formatted report of the qualification rankings.
|
||||
func RankingsJSONReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
rankings, err := db.GetAllRankings()
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
data, err := json.MarshalIndent(rankings, "", " ")
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.WriteString(w, string(data))
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a PDF-formatted report of the qualification rankings.
|
||||
func RankingsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
rankings, err := db.GetAllRankings()
|
||||
|
||||
1
web.go
1
web.go
@@ -62,6 +62,7 @@ func newHandler() http.Handler {
|
||||
router := mux.NewRouter()
|
||||
router.HandleFunc("/reports/csv/rankings", RankingsCsvReportHandler)
|
||||
router.HandleFunc("/reports/pdf/rankings", RankingsPdfReportHandler)
|
||||
router.HandleFunc("/reports/json/rankings", RankingsJSONReportHandler)
|
||||
router.HandleFunc("/reports/csv/schedule/{type}", ScheduleCsvReportHandler)
|
||||
router.HandleFunc("/reports/pdf/schedule/{type}", SchedulePdfReportHandler)
|
||||
router.HandleFunc("/reports/csv/teams", TeamsCsvReportHandler)
|
||||
|
||||
Reference in New Issue
Block a user