Skip to content

Commit cc32ba8

Browse files
committed
refac: reusing existing stop details api
1 parent a78809b commit cc32ba8

5 files changed

Lines changed: 86 additions & 59 deletions

File tree

3

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let LogLevel = < TRACE | DEBUG | INFO | WARN | ERROR | OFF >
2+
3+
let logger_cfg = {
4+
level = LogLevel.INFO,
5+
log_to_file = False
6+
}
7+
8+
let secrets = ../secrets/gtfs_in_memory_server_rust.example.dhall
9+
10+
in {
11+
-- Logger configuration
12+
logger_cfg = logger_cfg,
13+
14+
-- Database configuration
15+
database_url = Some ("psql://mtc_root_user:C%40uM7a%242025@13.234.6.205:5432/mtc_master_prod_new"),
16+
internal_database_url = Some ("psql://mtc_root_user:C%40uM7a%242025@13.234.6.205:5432/master_mtc_internal"),
17+
db_max_connections = 20,
18+
db_min_connections = 1,
19+
db_acquire_timeout = 5,
20+
db_idle_timeout = 600,
21+
db_max_lifetime = 3600,
22+
23+
-- Cache configuration
24+
cache_duration = 3600,
25+
26+
-- Trip filtering configuration
27+
ignored_trip_ids = ["t203"] : List Text,
28+
29+
-- API configuration
30+
port = 8000,
31+
32+
-- GTFS configuration
33+
polling_enabled = False,
34+
polling_interval = 10,
35+
process_batch_size = 100,
36+
gc_interval = 300,
37+
max_retries = 3,
38+
retry_delay = 5,
39+
rate_limit_delay = 0.1,
40+
cpu_threshold = 80.0,
41+
connection_limit = 100,
42+
memory_threshold = 1073741824,
43+
44+
-- HTTP configuration
45+
http_pool_idle_timeout = 90,
46+
http_tcp_keepalive = 7200,
47+
dns_ttl = 300,
48+
49+
-- OTP configuration
50+
otp_instances = {
51+
city_based_instances = [
52+
{ url = "https://api.sandbox.moving.tech/nandi", identifier = "chennai_bus" }
53+
],
54+
gtfs_id_based_instances = [] : List { identifier : Text, url : Text },
55+
default_instance = { url = "https://api.sandbox.moving.tech/nandi", identifier = "default" }
56+
},
57+
58+
-- Bhubaneswar vehicle cache configuration
59+
bhubaneswar_cache_update_interval = 10,
60+
phone_number_hash_key = "HASH_KEY",
61+
62+
enable_schedule_reconciliation=True,
63+
-- OSRTC station cache configuration
64+
osrtc_base_url = Some "OSRTC_BASE_URL",
65+
osrtc_username = secrets.osrtc_username,
66+
osrtc_secret_key = secrets.osrtc_secret_key,
67+
osrtc_station_refresh_interval_hours = 1,
68+
osrtc_feed_key = Some "odisha_osrtc"
69+
}

src/handlers/routes.rs

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::environment::AppState;
2424
use crate::graphql::TripQueryParams;
2525
use crate::models::{
2626
BusScheduleDetail, BusScheduleDetails, GTFSStop, MemoryUsageStats, MinimalEmployee,
27-
NandiRoutesRes, RouteStopMapping, StopClusterResponse, StopCodeFromProviderStopCodeResponse,
27+
NandiRoutesRes, RouteStopMapping, StopCodeFromProviderStopCodeResponse, StopDetailResponse,
2828
TripDetails, VehicleData, VehicleMetadataResponse, VehicleOperationData,
2929
VehicleServiceTypeResponse,
3030
};
@@ -206,10 +206,6 @@ pub fn create_routes(cfg: &mut actix_web::web::ServiceConfig) {
206206
"/cluster/{gtfs_id}/routes/{src_stop_code}/{dst_stop_code}",
207207
actix_web::web::get().to(get_routes_between_clusters_for_stops),
208208
)
209-
.route(
210-
"/stop/{gtfs_id}/{stop_code}/cluster",
211-
actix_web::web::get().to(get_stop_cluster),
212-
)
213209
.route("/ready", actix_web::web::get().to(readiness_probe))
214210
.route("/version/{gtfs_id}", actix_web::web::get().to(get_version))
215211
.route(
@@ -1155,30 +1151,6 @@ pub async fn get_routes_between_clusters_for_stops(
11551151
Ok(HttpResponse::Ok().json(routes))
11561152
}
11571153

1158-
#[utoipa::path(
1159-
get,
1160-
path = "/stop/{gtfs_id}/{stop_code}/cluster",
1161-
tag = "Cluster",
1162-
params(
1163-
("gtfs_id" = String, Path, description = "GTFS feed identifier"),
1164-
("stop_code" = String, Path, description = "Stop code"),
1165-
),
1166-
responses(
1167-
(status = 200, description = "Cluster id for the stop; cluster_id is null when the stop has no H3 cluster assigned.", body = StopClusterResponse),
1168-
(status = 404, description = "Unknown gtfs_id or stop_code")
1169-
)
1170-
)]
1171-
pub async fn get_stop_cluster(
1172-
app_state: Data<AppState>,
1173-
path: Path<(String, String)>,
1174-
) -> AppResult<HttpResponse> {
1175-
let (gtfs_id, stop_code) = path.into_inner();
1176-
let cluster_id = app_state
1177-
.gtfs_service
1178-
.get_stop_cluster_for_stop(&gtfs_id, &stop_code)?;
1179-
Ok(HttpResponse::Ok().json(StopClusterResponse { cluster_id }))
1180-
}
1181-
11821154
#[utoipa::path(
11831155
get,
11841156
path = "/routes/{gtfs_id}/fuzzy/{query}",
@@ -1293,7 +1265,7 @@ pub fn merge_stop_and_mapping(
12931265
("gtfs_id" = String, Path, description = "GTFS feed identifier"),
12941266
("stop_code" = String, Path, description = "Stop code"),
12951267
),
1296-
responses((status = 200, description = "Stop details", body = RouteStopMapping))
1268+
responses((status = 200, description = "Stop details", body = StopDetailResponse))
12971269
)]
12981270
pub async fn get_stop(
12991271
app_state: Data<AppState>,
@@ -1309,14 +1281,21 @@ pub async fn get_stop(
13091281
.get_station_by_id(&stop_code)
13101282
.await
13111283
.ok_or_else(|| AppError::NotFound(format!("OSRTC station not found: {stop_code}")))?;
1312-
return Ok(HttpResponse::Ok().json(osrtc_station_to_route_stop_mapping(&station)));
1284+
return Ok(HttpResponse::Ok().json(StopDetailResponse {
1285+
mapping: osrtc_station_to_route_stop_mapping(&station),
1286+
cluster_id: None,
1287+
}));
13131288
}
13141289
let (stop, maybe_mapping) = app_state
13151290
.gtfs_service
13161291
.get_stop(&gtfs_id, &stop_code)
13171292
.await?;
1318-
let merged_stop = merge_stop_and_mapping(stop, maybe_mapping);
1319-
Ok(HttpResponse::Ok().json(merged_stop))
1293+
let cluster_id = stop.cluster_id.clone();
1294+
let mapping = merge_stop_and_mapping(stop, maybe_mapping);
1295+
Ok(HttpResponse::Ok().json(StopDetailResponse {
1296+
mapping,
1297+
cluster_id,
1298+
}))
13201299
}
13211300

13221301
#[utoipa::path(

src/models.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ pub struct GTFSStop {
459459
}
460460

461461
#[derive(Debug, Clone, Serialize, ToSchema)]
462-
pub struct StopClusterResponse {
462+
pub struct StopDetailResponse {
463+
#[serde(flatten)]
464+
pub mapping: RouteStopMapping,
465+
#[serde(rename = "clusterId", skip_serializing_if = "Option::is_none")]
463466
pub cluster_id: Option<String>,
464467
}
465468

src/services/gtfs_service.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,29 +1637,6 @@ impl GTFSService {
16371637
Ok(out)
16381638
}
16391639

1640-
pub fn get_stop_cluster_for_stop(
1641-
&self,
1642-
gtfs_id: &str,
1643-
stop_code: &str,
1644-
) -> AppResult<Option<String>> {
1645-
let data = self.data.load_full();
1646-
let gtfs_id = clean_identifier(gtfs_id);
1647-
let stop_code = clean_identifier(stop_code);
1648-
1649-
let stops_data = data.stops_by_gtfs.get(&gtfs_id).ok_or_else(|| {
1650-
AppError::NotFound(format!("Stops data not found for gtfs_id: {}", gtfs_id))
1651-
})?;
1652-
1653-
let stop = stops_data.stops.get(&stop_code).ok_or_else(|| {
1654-
AppError::NotFound(format!(
1655-
"Stop not found for stop_code: {} under gtfs_id: {}",
1656-
stop_code, gtfs_id
1657-
))
1658-
})?;
1659-
1660-
Ok(stop.cluster_id.clone())
1661-
}
1662-
16631640
pub fn get_routes_between_clusters_for_stops(
16641641
&self,
16651642
gtfs_id: &str,

src/swagger.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use crate::services::operator::QueryBody;
5050
routes::get_all_route_stop_mappings_by_stop_codes,
5151
routes::get_cluster_destinations,
5252
routes::get_routes_between_clusters_for_stops,
53-
routes::get_stop_cluster,
5453
routes::get_all_vehicles_by_ids,
5554
routes::get_routes_by_ids,
5655
// Trip
@@ -118,7 +117,7 @@ use crate::services::operator::QueryBody;
118117
models::BusScheduleDetail,
119118
models::BusStopETA,
120119
models::StopCodeFromProviderStopCodeResponse,
121-
models::StopClusterResponse,
120+
models::StopDetailResponse,
122121
models::MemoryUsageStats,
123122
models::TripDetails,
124123
models::TripStopDetail,

0 commit comments

Comments
 (0)