Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nav 16 setup spring with rest #20

Merged
merged 11 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ch.naviqore</groupId>
<artifactId>naviqore-raptor</artifactId>
<version>1.0.0-SNAPSHOT</version>
Expand Down Expand Up @@ -42,6 +47,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>21</java.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
Expand Down Expand Up @@ -72,6 +78,10 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -135,6 +145,26 @@
<artifactId>commons-csv</artifactId>
<version>1.10.0</version>
</dependency>
<!-- api-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.1.12</version>
</dependency>
</dependencies>

</project>
13 changes: 13 additions & 0 deletions src/main/java/ch/naviqore/app/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ch.naviqore.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}
442 changes: 442 additions & 0 deletions src/main/java/ch/naviqore/app/controller/DummyData.java

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions src/main/java/ch/naviqore/app/controller/RoutingController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ch.naviqore.app.controller;

import ch.naviqore.app.model.Connection;
import ch.naviqore.app.model.EarliestArrival;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/routing")
public class RoutingController {

@GetMapping("/connections")
public List<Connection> getConnections(@RequestParam String sourceStopId, @RequestParam String targetStopId,
@RequestParam(required = false) LocalDateTime departureDateTime,
@RequestParam(required = false, defaultValue = "2147483647") int maxWalkingDuration,
@RequestParam(required = false, defaultValue = "2147483647") int maxTransferNumber,
@RequestParam(required = false, defaultValue = "2147483647") int maxTravelTime,
@RequestParam(required = false, defaultValue = "0") int minTransferTime) {
// TODO: Implement the method with maxWalkingDuration, maxTransferNumber, maxTravelTime, minTransferTime
return DummyData.getConnections(sourceStopId, targetStopId, departureDateTime);
}

@GetMapping("/isolines")
public List<EarliestArrival> getIsolines(@RequestParam String sourceStopId,
@RequestParam(required = false) LocalDateTime departureDateTime,
@RequestParam(required = false, defaultValue = "2147483647") int maxWalkingDuration,
@RequestParam(required = false, defaultValue = "2147483647") int maxTransferNumber,
@RequestParam(required = false, defaultValue = "2147483647") int maxTravelTime,
@RequestParam(required = false, defaultValue = "0") int minTransferTime) {
// TODO: Implement the method with maxWalkingDuration, maxTransferNumber, minTransferTime
return DummyData.getIsolines(sourceStopId, departureDateTime, maxTravelTime);
}

}
43 changes: 43 additions & 0 deletions src/main/java/ch/naviqore/app/controller/ScheduleController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ch.naviqore.app.controller;

import ch.naviqore.app.model.Departure;
import ch.naviqore.app.model.DistanceToStop;
import ch.naviqore.app.model.SearchType;
import ch.naviqore.app.model.Stop;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/schedule")
public class ScheduleController {

@GetMapping("/stops/autocomplete")
public List<Stop> getAutoCompleteStops(@RequestParam String query,
@RequestParam(required = false, defaultValue = "10") int limit,
@RequestParam(required = false, defaultValue = "FUZZY") SearchType type) {
return DummyData.searchStops(query, limit, type);
}

@GetMapping("/stops/nearest")
public List<DistanceToStop> getNearestStops(@RequestParam double latitude, @RequestParam double longitude,
@RequestParam(required = false, defaultValue = "1000") int maxDistance,
@RequestParam(required = false, defaultValue = "10") int limit) {
return DummyData.getNearestStops(latitude, longitude, maxDistance, limit);
}

@GetMapping("/stops/{stopId}")
public Stop getStop(@PathVariable String stopId) {
return DummyData.getStop(stopId);
}

@GetMapping("/stops/{stopId}/departures")
public List<Departure> getDepartures(@PathVariable String stopId,
@RequestParam(required = false) LocalDateTime departureDateTime,
@RequestParam(required = false, defaultValue = "10") int limit,
@RequestParam(required = false) LocalDateTime untilDateTime) {
return DummyData.getDepartures(stopId, departureDateTime, limit, untilDateTime);
}

}
19 changes: 19 additions & 0 deletions src/main/java/ch/naviqore/app/model/Connection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

import java.util.List;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class Connection {

private final List<Leg> legs;

}

18 changes: 18 additions & 0 deletions src/main/java/ch/naviqore/app/model/Coordinate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class Coordinate {

private final double latitude;
private final double longitude;

}

18 changes: 18 additions & 0 deletions src/main/java/ch/naviqore/app/model/Departure.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class Departure {

private final StopTime stopTime;
private final Trip trip;

}

18 changes: 18 additions & 0 deletions src/main/java/ch/naviqore/app/model/DistanceToStop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class DistanceToStop {

private final Stop stop;
private final double distance;

}

23 changes: 23 additions & 0 deletions src/main/java/ch/naviqore/app/model/EarliestArrival.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class EarliestArrival {

private final Stop stop;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private final LocalDateTime arrivalTime;
private final Connection connection;

}

29 changes: 29 additions & 0 deletions src/main/java/ch/naviqore/app/model/Leg.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

@RequiredArgsConstructor
@EqualsAndHashCode
@ToString
@Getter
public class Leg {

private final Coordinate from;
private final Coordinate to;
private final Stop fromStop;
private final Stop toStop;
private final LegType type;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private final LocalDateTime departureTime;
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private final LocalDateTime arrivalTime;
private final Trip trip;

}

33 changes: 33 additions & 0 deletions src/main/java/ch/naviqore/app/model/LegType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ch.naviqore.app.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@ToString
public enum LegType {

WALK("WALK"),
ROUTE("ROUTE");

private final String value;

@JsonCreator
public static LegType fromValue(String value) {
for (LegType b : LegType.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

@JsonValue
public String getValue() {
return value;
}
}

20 changes: 20 additions & 0 deletions src/main/java/ch/naviqore/app/model/Route.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@EqualsAndHashCode(of = "id")
@ToString
@Getter
public class Route {

private final String id;
private final String name;
private final String shortName;
private final String transportMode;

}

35 changes: 35 additions & 0 deletions src/main/java/ch/naviqore/app/model/SearchType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.naviqore.app.model;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum SearchType {

EXACT("EXACT"),
STARTS_WITH("STARTS_WITH"),
CONTAINS("CONTAINS"),
ENDS_WITH("ENDS_WITH"),
FUZZY("FUZZY");

private final String value;

@JsonCreator
public static SearchType fromValue(String value) {
for (SearchType b : SearchType.values()) {
if (b.value.equals(value)) {
return b;
}
}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
}

@JsonValue
public String getValue() {
return value;
}

}

19 changes: 19 additions & 0 deletions src/main/java/ch/naviqore/app/model/Stop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ch.naviqore.app.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@RequiredArgsConstructor
@EqualsAndHashCode(of = "id")
@ToString
@Getter
public class Stop {

private final String id;
private final String name;
private final Coordinate coordinates;

}

Loading
Loading