Skip to content

Commit

Permalink
Route details by stop id (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
TsimurSh authored Jun 2, 2024
1 parent cedd9d8 commit 65c969f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,26 @@ ResponseEntity<ApiRoutesDetailsResponse> getRouteDetails(
@RequestParam(value = "tripPattern", required = false)
String tripPatternId);

/**
* Handles the "routesDetails" command for specified stop ID. Provides detailed information for a route includes all
* stops and paths.
*
* @param stdParameters
*
* @return
*/
@GetMapping(value = "/command/routesDetailsByStopId",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
@Operation(
summary = "Provides detailed information for a route.",
description = "Provides detailed information for a route includes specified stop Id "
+ "and paths such that it can be drawn in a map.",
tags = {"base data", "route"})
ResponseEntity<ApiRoutesDetailsResponse> getRouteDetailsByStopId(
StandardParameters stdParameters,
@Parameter(description = "Stop id") @RequestParam(value = "id")
String stopId);

/**
* Handles the "stops" command. Returns all stops associated with a route, grouped by direction.
* Useful for creating a UI where user needs to select a stop from a list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,20 @@ public ResponseEntity<ApiRoutesDetailsResponse> getRouteDetails(
// ApiRoutesDetails object
ApiRoutesDetailsResponse routeData = new ApiRoutesDetailsResponse(ipcRoutes, agencies.get(0));
return stdParameters.createResponse(routeData);
}

@Override
public ResponseEntity<ApiRoutesDetailsResponse> getRouteDetailsByStopId(
StandardParameters stdParameters,
String stopId) {
// Get agency info so can also return agency name
List<Agency> agencies = configService.getAgencies();
// Retrieve filtered routs
var ipcRoutes = configService.getRoutesByStopId(stopId);
// Take the IpcRoute data array and create and return
// ApiRoutesDetails object
ApiRoutesDetailsResponse routeData = new ApiRoutesDetailsResponse(ipcRoutes, agencies.get(0));
return stdParameters.createResponse(routeData);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* (C)2023 */
package org.transitclock.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.transitclock.core.dataCache.PredictionDataCache;
import org.transitclock.core.dataCache.VehicleDataCache;
import org.transitclock.domain.structs.Agency;
Expand All @@ -28,10 +30,9 @@
import org.transitclock.service.dto.IpcTripPattern;
import org.transitclock.service.dto.IpcVehicleComplete;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
* Implements ConfigInterface to serve up configuration information to RMI clients.
Expand Down Expand Up @@ -372,4 +373,20 @@ public List<String> getBlockIds(String serviceId) {
.distinct()
.collect(Collectors.toList());
}
}

/* (non-Javadoc)
* @see org.transitclock.ipc.interfaces.ConfigInterface#getRoutesByStopId()
*/
@Override
public List<IpcRoute> getRoutesByStopId(String stopId) {
return dbConfig.getRoutesForStop(stopId)
.stream()
.map(dbRoute -> new IpcRoute(dbRoute,
dbConfig,
null,
null,
null,
null))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,12 @@ IpcRoute getRoute(String routeIdOrShortName, String directionId, String stopId,
* @return vehicle IDs
*/
List<String> getBlockIds(String serviceId);

/**
* Obtains list of routes which contained stops with following stop ID
*
* @param stopId
* @return list of IpcRoute
*/
List<IpcRoute> getRoutesByStopId(String stopId);
}

0 comments on commit 65c969f

Please sign in to comment.