mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 11:54:59 -04:00
Backend-only re-cut of the #76 availability work onto main, stacked on the canonical Weekend Context API. Adds request-scoped freshness reporting so aggregate responses cannot report fresh when a component is stale, plus local-first driver summary resolution and cache/pacing truth. The frontend half of #76 is deliberately excluded: it is built on the Weekend shell that failed owner review, including the full-width Partial banner treatment. Availability presentation is re-cut with the shell in #89. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package web
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/AmanTahiliani/box-box/internal/query"
|
|
)
|
|
|
|
func (s *Server) handleSeasons(w http.ResponseWriter, r *http.Request) {
|
|
markLocalResponse(w, false)
|
|
if !s.hasLocalQuery() {
|
|
writeJSON(w, []int{})
|
|
return
|
|
}
|
|
|
|
years, err := s.query.ListSeasons()
|
|
if err != nil {
|
|
writeError(w, err, http.StatusInternalServerError, false)
|
|
return
|
|
}
|
|
if years == nil {
|
|
years = []int{}
|
|
}
|
|
writeJSON(w, years)
|
|
}
|
|
|
|
func (s *Server) handleWeekend(w http.ResponseWriter, r *http.Request) {
|
|
markLocalResponse(w, false)
|
|
meetingKey, err := strconv.Atoi(r.URL.Query().Get("meeting_key"))
|
|
if err != nil || meetingKey == 0 {
|
|
http.Error(w, "meeting_key required", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
if !s.hasLocalQuery() {
|
|
writeError(w, query.ErrMeetingNotFound, http.StatusNotFound, false)
|
|
return
|
|
}
|
|
|
|
weekend, err := s.query.GetWeekend(meetingKey)
|
|
if err != nil {
|
|
if errors.Is(err, query.ErrMeetingNotFound) {
|
|
writeError(w, err, http.StatusNotFound, false)
|
|
return
|
|
}
|
|
writeError(w, err, http.StatusInternalServerError, false)
|
|
return
|
|
}
|
|
markLocalResponse(w, weekend.Source == query.ResponseSourcePartial)
|
|
writeJSON(w, weekend)
|
|
}
|