fix: address code review findings
This commit is contained in:
@@ -2,6 +2,7 @@ package routing
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
"trip-planner/internal/storage"
|
||||
@@ -626,9 +627,10 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
"date": time.Now().Format("2006-01-02"),
|
||||
}
|
||||
|
||||
resp, err := yandexClient.Do(context.Background(), "GET", "/v3.0/search/", query)
|
||||
resp, err := yandexClient.Do(context.TODO(), "GET", "/v3.0/search/", query)
|
||||
if err != nil {
|
||||
// If API call fails, return nil (no route found)
|
||||
// If API call fails, log the error and return nil (no route found)
|
||||
log.Printf("WARNING: yandex search failed for route expansion: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1106,9 +1108,9 @@ func (g *Graph) checkRouteForChanges(itinerary *Itinerary) bool {
|
||||
|
||||
// rescheduleRoute performs a re-search for the route with updated graph data.
|
||||
// This is called when significant changes are detected in the route legs.
|
||||
func (g *Graph) rescheduleRoute(originID, destID string, opts SearchOptions, closedStations map[string]bool, neighbors map[string][]storage.StationNeighbor) *Itinerary {
|
||||
func (g *Graph) rescheduleRoute(originID, destID string, opts SearchOptions, closedStations map[string]bool, neighbors map[string][]storage.StationNeighbor, yclient ...*yandex.Client) *Itinerary {
|
||||
// Re-run the search with the same options to get an updated route
|
||||
result := g.FindRoute(originID, destID, opts, closedStations, neighbors)
|
||||
result := g.FindRoute(originID, destID, opts, closedStations, neighbors, yclient...)
|
||||
if result != nil {
|
||||
result.LastChecked = time.Now().Unix()
|
||||
result.NeedsReSearch = false
|
||||
@@ -1119,9 +1121,9 @@ func (g *Graph) rescheduleRoute(originID, destID string, opts SearchOptions, clo
|
||||
|
||||
// CheckAndRescheduleRoute checks a route for changes and returns an updated route if needed.
|
||||
// This is the main entry point for flight change notification logic.
|
||||
func (g *Graph) CheckAndRescheduleRoute(itinerary *Itinerary, originID, destID string, opts SearchOptions, closedStations map[string]bool, neighbors map[string][]storage.StationNeighbor) *Itinerary {
|
||||
func (g *Graph) CheckAndRescheduleRoute(itinerary *Itinerary, originID, destID string, opts SearchOptions, closedStations map[string]bool, neighbors map[string][]storage.StationNeighbor, yclient ...*yandex.Client) *Itinerary {
|
||||
if g.checkRouteForChanges(itinerary) {
|
||||
return g.rescheduleRoute(originID, destID, opts, closedStations, neighbors)
|
||||
return g.rescheduleRoute(originID, destID, opts, closedStations, neighbors, yclient...)
|
||||
}
|
||||
return itinerary
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user