-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add journey planner and real time endpoints
- Loading branch information
Showing
15 changed files
with
1,031 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
server/src/main/java/de/davelee/trams/server/controller/JourneyPlannerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package de.davelee.trams.server.controller; | ||
|
||
import de.davelee.trams.server.request.JourneyRequest; | ||
import de.davelee.trams.server.response.JourneyResponse; | ||
import de.davelee.trams.server.service.CalculateJourneyService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
/** | ||
* This class provides REST endpoints which provide operations associated with journey planning in the TraMS Server API. | ||
* @author Dave Lee | ||
*/ | ||
@RestController | ||
@Tag(name="/api/journeyPlanner") | ||
@RequestMapping(value="/api/journeyPlanner") | ||
public class JourneyPlannerController { | ||
|
||
@Autowired | ||
private CalculateJourneyService calculateJourneyService; | ||
|
||
/** | ||
* Calculate the journey based on the supplied journey request. | ||
* @param journeyRequest a <code>JourneyRequest</code> object containing the journey that should be calculated. | ||
* @return a <code>JourneyResponse</code> object containing either the journey instructions or an error message if | ||
* no journey could be calculated. | ||
*/ | ||
@PostMapping("/determineJourney") | ||
@CrossOrigin | ||
@ResponseBody | ||
@Operation(summary = "Suggest a journey based on the request journey parameters", description="Return proposed journey") | ||
public JourneyResponse determineJourney (@RequestBody final JourneyRequest journeyRequest) { | ||
//Create a journeyResponse object. | ||
JourneyResponse journeyResponse = new JourneyResponse(); | ||
//If the start equals the destination then return an error message. | ||
if ( journeyRequest.getFrom().contentEquals(journeyRequest.getTo()) ) { | ||
journeyResponse.setErrorMessage("Cannot suggest route as start and end points are identical!"); | ||
} else { | ||
//Otherwise, calculate journey and generate a list of instructions. | ||
journeyResponse.setJourneyInstructionList(calculateJourneyService.calculateJourney(journeyRequest)); | ||
//If the instructions is empty then produce an error message. | ||
if ( journeyResponse.getJourneyInstructionList().size() == 0 ) { | ||
journeyResponse.setErrorMessage("No journeys found!"); | ||
} | ||
} | ||
//Generate journey response. | ||
return journeyResponse; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
server/src/main/java/de/davelee/trams/server/model/Address.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package de.davelee.trams.server.model; | ||
|
||
import lombok.*; | ||
import org.bson.types.ObjectId; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
/** | ||
* This class represents an address which is mapped to a particular stop. This stop is the closest stop to this address. | ||
* @author Dave Lee | ||
*/ | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
@Builder | ||
@Document | ||
public class Address { | ||
|
||
/** | ||
* A unique id for this address. | ||
*/ | ||
@Id | ||
private ObjectId id; | ||
|
||
/** | ||
* The operator which serves this address. | ||
*/ | ||
private String addressOperator; | ||
|
||
/** | ||
* The address that can be searched for. | ||
*/ | ||
private String address; | ||
|
||
/** | ||
* The stop that serves this address. | ||
*/ | ||
private Stop stop; | ||
|
||
/** | ||
* The distance between stop and address in minutes. | ||
*/ | ||
private int durationInMins; | ||
|
||
} |
Oops, something went wrong.