fix: address code review findings
- Fix type mismatch in search_cache.go: SearchWithCache now returns *yandex.Response instead of *Itinerary - Fix token bucket refill logic in yandex/client.go to properly accumulate tokens based on refillPerSec - Fix hardcoded API key in main.go to load from YANDEX_API_KEY environment variable - Fix missing error handling for JSON encoding in handlers.go RouteGeoJSON function - Fix incorrect redis.Nil handling in cache/store.go CacheAside.Exists method - Fix incorrect error return type in station_status.go updateStationStatus to return newStatus instead of empty string
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
|
||||
"trip-planner/internal/metrics"
|
||||
"trip-planner/internal/airports"
|
||||
"trip-planner/internal/metrics"
|
||||
"trip-planner/internal/routing"
|
||||
"trip-planner/internal/storage"
|
||||
"trip-planner/internal/yandex"
|
||||
@@ -216,25 +216,25 @@ func TestRouteGeoJSON(t *testing.T) {
|
||||
graph.AddNode(&routing.Node{ID: "s3", Type: routing.NodeTypeStation, Name: "Station 3", CityCode: "c1"})
|
||||
// Add a real edge s1 → s2
|
||||
graph.AddEdge(&routing.Edge{
|
||||
From: graph.Nodes()[0],
|
||||
To: graph.Nodes()[1],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 3600,
|
||||
Transport: "train",
|
||||
From: graph.Nodes()[0],
|
||||
To: graph.Nodes()[1],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 3600,
|
||||
Transport: "train",
|
||||
TransportType: routing.TransportTypeTrain,
|
||||
IsTransfer: false,
|
||||
Synthetic: false,
|
||||
IsTransfer: false,
|
||||
Synthetic: false,
|
||||
})
|
||||
// Add a synthetic edge s2 → s3 (city↔airport transfer)
|
||||
graph.AddEdge(&routing.Edge{
|
||||
From: graph.Nodes()[1],
|
||||
To: graph.Nodes()[2],
|
||||
Kind: routing.EdgeKindSynthetic,
|
||||
Duration: 300,
|
||||
Transport: "train",
|
||||
From: graph.Nodes()[1],
|
||||
To: graph.Nodes()[2],
|
||||
Kind: routing.EdgeKindSynthetic,
|
||||
Duration: 300,
|
||||
Transport: "train",
|
||||
TransportType: routing.TransportTypeTrain,
|
||||
IsTransfer: true,
|
||||
Synthetic: true,
|
||||
IsTransfer: true,
|
||||
Synthetic: true,
|
||||
})
|
||||
h.Router = graph
|
||||
|
||||
@@ -305,25 +305,25 @@ func TestGeoJSONVisualization(t *testing.T) {
|
||||
|
||||
// Add real edge Moscow → Transfer
|
||||
graph.AddEdge(&routing.Edge{
|
||||
From: graph.Nodes()[0],
|
||||
To: graph.Nodes()[1],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 1800,
|
||||
Transport: "train",
|
||||
From: graph.Nodes()[0],
|
||||
To: graph.Nodes()[1],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 1800,
|
||||
Transport: "train",
|
||||
TransportType: routing.TransportTypeTrain,
|
||||
IsTransfer: false,
|
||||
Synthetic: false,
|
||||
IsTransfer: false,
|
||||
Synthetic: false,
|
||||
})
|
||||
// Add transfer edge Transfer → Destination
|
||||
graph.AddEdge(&routing.Edge{
|
||||
From: graph.Nodes()[1],
|
||||
To: graph.Nodes()[2],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 1800,
|
||||
Transport: "train",
|
||||
From: graph.Nodes()[1],
|
||||
To: graph.Nodes()[2],
|
||||
Kind: routing.EdgeKindReal,
|
||||
Duration: 1800,
|
||||
Transport: "train",
|
||||
TransportType: routing.TransportTypeTrain,
|
||||
IsTransfer: true,
|
||||
Synthetic: false,
|
||||
IsTransfer: true,
|
||||
Synthetic: false,
|
||||
})
|
||||
h.Router = graph
|
||||
|
||||
@@ -356,19 +356,19 @@ func TestGeoJSONVisualization(t *testing.T) {
|
||||
if geomType == "Point" {
|
||||
props, ok := feature["properties"].(map[string]interface{})
|
||||
if ok {
|
||||
markerType, ok := props["marker_type"].(string)
|
||||
if ok && markerType == "transfer" {
|
||||
hasTransferMarker = true
|
||||
// Verify popup-related properties exist
|
||||
_, hasConnTime := props["connection_time"]
|
||||
_, hasTransferType := props["transfer_type"]
|
||||
if !hasConnTime {
|
||||
t.Error("expected connection_time property in transfer marker")
|
||||
}
|
||||
if !hasTransferType {
|
||||
t.Error("expected transfer_type property in transfer marker")
|
||||
}
|
||||
}
|
||||
markerType, ok := props["marker_type"].(string)
|
||||
if ok && markerType == "transfer" {
|
||||
hasTransferMarker = true
|
||||
// Verify popup-related properties exist
|
||||
_, hasConnTime := props["connection_time"]
|
||||
_, hasTransferType := props["transfer_type"]
|
||||
if !hasConnTime {
|
||||
t.Error("expected connection_time property in transfer marker")
|
||||
}
|
||||
if !hasTransferType {
|
||||
t.Error("expected transfer_type property in transfer marker")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -968,4 +968,4 @@ func TestUserPreferences(t *testing.T) {
|
||||
t.Error("expected at least 1 search history entry")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user