mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-07 19:56:18 -04:00
Add local navigation API
This commit is contained in:
50
internal/web/navigation.go
Normal file
50
internal/web/navigation.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/AmanTahiliani/box-box/internal/query"
|
||||
)
|
||||
|
||||
func (s *Server) handleSeasons(w http.ResponseWriter, r *http.Request) {
|
||||
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) {
|
||||
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
|
||||
}
|
||||
writeJSON(w, weekend)
|
||||
}
|
||||
Reference in New Issue
Block a user