Skip to content

Commit 5b3d501

Browse files
authored
[2/2] Fix v3 naming schemes & add back dummy endpoints to ensure back compat (#313)
1 parent 61680b9 commit 5b3d501

7 files changed

Lines changed: 51 additions & 8 deletions

File tree

src/API.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class API extends ApplicationAPI {
2323
Routers.MultiRouteRouter,
2424
Routers.PlacesAutocompleteRouter,
2525
Routers.PlaceIDCoordinatesRouter,
26+
Routers.RouteSelectedRouter,
2627
Routers.SearchRouter,
2728
];
2829
return {

src/routers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import MultiRouteRouter from './v1/MultiRouteRouter';
1111
import PlacesAutocompleteRouter from './v1/PlacesAutocompleteRouter';
1212
import PlaceIDCoordinatesRouter from './v1/PlaceIDCoordinatesRouter';
1313
import RouteRouter from './v1/RouteRouter';
14+
import RouteSelectedRouter from './v1/RouteSelectedRouter';
1415
import RouteV2Router from './v2/RouteRouter';
1516
import RouteV3Router from './v3/RouteRouter';
1617
import SearchRouter from './v1/SearchRouter';
@@ -31,6 +32,7 @@ export default {
3132
PlacesAutocompleteRouter,
3233
PlaceIDCoordinatesRouter,
3334
RouteRouter,
35+
RouteSelectedRouter,
3436
RouteV2Router,
3537
RouteV3Router,
3638
SearchRouter,

src/routers/v1/RouteRouter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
import type Request from 'express';
3+
import AnalyticsUtils from '../../utils/AnalyticsUtils';
34
import ApplicationRouter from '../../appdev/ApplicationRouter';
45
import LogUtils from '../../utils/LogUtils';
56
import RouteUtils from '../../utils/RouteUtils';
@@ -42,6 +43,8 @@ class RouteRouter extends ApplicationRouter<Array<Object>> {
4243
};
4344
LogUtils.log({ category: 'routeRequestWithTransfer', request });
4445
}
46+
AnalyticsUtils.assignRouteIdsAndCache(routes);
47+
4548
return routes;
4649
}
4750
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @flow
2+
import type Request from 'express';
3+
import ApplicationRouter from '../../appdev/ApplicationRouter';
4+
5+
class RouteSelectedRouter extends ApplicationRouter<Array<Object>> {
6+
constructor() {
7+
super(['POST']);
8+
}
9+
10+
getPath(): string {
11+
return '/routeSelected/';
12+
}
13+
14+
// eslint-disable-next-line require-await
15+
async content(req: Request): Promise<any> {
16+
return null;
17+
}
18+
}
19+
20+
export default new RouteSelectedRouter().router;

src/routers/v2/RouteRouter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
import type Request from 'express';
3+
import AnalyticsUtils from '../../utils/AnalyticsUtils';
34
import ApplicationRouter from '../../appdev/ApplicationRouter';
45
import LogUtils from '../../utils/LogUtils';
56
import RouteUtils from '../../utils/RouteUtils';
@@ -44,13 +45,14 @@ class RouteRouter extends ApplicationRouter<Object> {
4445
destinationName,
4546
end: routes[0].endCoords,
4647
originName,
47-
routeId: routes[0].routeId,
48+
routeId: null,
4849
start: routes[0].startCoords,
4950
time,
5051
uid,
5152
};
5253
LogUtils.log({ category: 'routeRequest', request });
5354
}
55+
AnalyticsUtils.assignRouteIdsAndCache(routes);
5456
return sectionedRoutes;
5557
}
5658
}

src/utils/AnalyticsUtils.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @flow
2+
import crypto from 'crypto';
3+
4+
function getUniqueId(numBytes: ?number = 10) {
5+
return crypto.randomBytes(numBytes).toString('hex');
6+
}
7+
8+
function assignRouteIdsAndCache(routeRes: Object[]) {
9+
routeRes.forEach((route) => {
10+
route.routeId = getUniqueId();
11+
});
12+
}
13+
14+
export default {
15+
getUniqueId,
16+
assignRouteIdsAndCache,
17+
};

src/utils/RealtimeFeedUtilsV3.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ async function fetchVehicles(): Object {
2323
}
2424

2525
/**
26-
* Given an array of { routeID, tripID },
26+
* Given an array of { routeId, tripId },
2727
* Return bus information
2828
* Input:[
2929
* {
30-
* routeID : String,
31-
* tripID : String
30+
* routeId : String,
31+
* tripId : String
3232
* },... ]
33-
* NOTE: Because we need to provide backwards compatibility with old iOS clients
34-
* we have to follow their janky way of routeID input is String but routeID
35-
* output is Number. This "routeID" is also named jankily, which is supposed to
36-
* be routeNumber from v2/route/. We cast this to Number in getVehicleInformation.
33+
* Corresponds to GTFS RouteId and TripId.
3734
*
3835
*
3936
*/
@@ -116,6 +113,7 @@ function getVehicleInformation(
116113
return null;
117114
}
118115
const vehicleData = Object.values(vehicles).find(
116+
// Naming here is routeID and tripID due to how the microservice names fields
119117
v => (v.routeID === routeId) && (v.tripID === tripId),
120118
);
121119
if (!vehicleData) {

0 commit comments

Comments
 (0)