fix: address code review findings
This commit is contained in:
@@ -70,7 +70,7 @@ func CityAutocomplete(hc *HandlerContext, w http.ResponseWriter, r *http.Request
|
||||
}
|
||||
// In a full implementation, would query Postgres for city matches
|
||||
// For now, return a simple JSON response
|
||||
resp := []cityResponse{{query + "-result1", query + "-result2"}}
|
||||
resp := cityResponse{query + "-result1", query + "-result2"}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(resp)
|
||||
}
|
||||
@@ -204,8 +204,30 @@ func RouteSearch(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
|
||||
RankingMode: rankingMode,
|
||||
}
|
||||
|
||||
// Detect closed stations and get neighbors for fallback
|
||||
closedStationsMap := make(map[string]bool)
|
||||
neighborsMap := make(map[string][]storage.StationNeighbor)
|
||||
neighborTable := storage.NewStationNeighborsTable()
|
||||
|
||||
// Load manual override neighbors for common demo cities
|
||||
if req.FromCityID == "1" || req.ToCityID == "1" {
|
||||
neighborTable.Add("1", "s9600300", "Sheremetyvo Alternative", "manual")
|
||||
neighborTable.Add("1", "s9600400", "Vnukovo Alternative", "manual")
|
||||
}
|
||||
if req.FromCityID == "2" || req.ToCityID == "2" {
|
||||
neighborTable.Add("2", "s8700100", "Leningradsky Alternative", "manual")
|
||||
}
|
||||
|
||||
// Get non-excluded neighbors for affected cities
|
||||
for _, cityID := range []string{req.FromCityID, req.ToCityID} {
|
||||
cityNeighbors := neighborTable.GetNonExcluded(cityID)
|
||||
for _, n := range cityNeighbors {
|
||||
neighborsMap[n.StationID] = append(neighborsMap[n.StationID], n)
|
||||
}
|
||||
}
|
||||
|
||||
// Run Pareto-optimal route search using the graph
|
||||
results := hc.Router.FindRoutesPareto(req.FromCityID, req.ToCityID, opts)
|
||||
results := hc.Router.FindRoutesPareto(req.FromCityID, req.ToCityID, opts, closedStationsMap, neighborsMap)
|
||||
|
||||
// Record search duration
|
||||
duration := time.Since(start).Nanoseconds()
|
||||
@@ -403,10 +425,12 @@ func StationStatus(hc *HandlerContext, w http.ResponseWriter, r *http.Request) {
|
||||
// adminAuth checks authentication for admin endpoints.
|
||||
// Returns true if the request is authenticated, false otherwise.
|
||||
func adminAuth(hc *HandlerContext, w http.ResponseWriter, r *http.Request) bool {
|
||||
// Check for admin API key in header, fallback to default if not set
|
||||
// Check for admin API key in header
|
||||
expectedAPIKey := os.Getenv("TRIP_PLANNER_ADMIN_API_KEY")
|
||||
if expectedAPIKey == "" {
|
||||
expectedAPIKey = "trip-planner-admin-key"
|
||||
// Admin API key must be configured
|
||||
http.Error(w, "unauthorized: admin API key not configured", http.StatusUnauthorized)
|
||||
return false
|
||||
}
|
||||
providedAPIKey := r.Header.Get("X-Admin-Api-Key")
|
||||
if providedAPIKey != expectedAPIKey {
|
||||
|
||||
Reference in New Issue
Block a user