fix: address code review findings

This commit is contained in:
2026-08-18 14:25:34 +03:00
parent 48650d96cf
commit 0d603ad15f
6 changed files with 56 additions and 24 deletions

View File

@@ -205,6 +205,18 @@ func RouteSearch(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
RankingMode: rankingMode,
}
// Determine if this is a far-term search (date is more than 7 days in the future)
if req.Date != "" {
requestDate, err := time.Parse("2006-01-02", req.Date)
if err == nil {
now := time.Now()
daysDiff := int(requestDate.Sub(now).Hours() / 24)
if daysDiff >= 7 {
opts.FarTerm = true
}
}
}
// Detect closed stations and get neighbors for fallback
closedStationsMap := make(map[string]bool)
neighborsMap := make(map[string][]storage.StationNeighbor)
@@ -431,7 +443,7 @@ func StationStatus(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
func adminAuth(hc *HandlerContext, w http.ResponseWriter, r *http.Request) bool {
expectedAPIKey := os.Getenv("TRIP_PLANNER_ADMIN_API_KEY")
if expectedAPIKey == "" {
http.Error(w, "unauthorized", http.StatusUnauthorized)
http.Error(w, "server configuration error: TRIP_PLANNER_ADMIN_API_KEY is not set", http.StatusInternalServerError)
return false
}
providedAPIKey := r.Header.Get("X-Admin-Api-Key")