update alternative routing dto structure according to meeting results
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -52,7 +52,7 @@ public class CartaClient {
|
||||
return cartaApi.getDirection(
|
||||
origin,
|
||||
destination,
|
||||
mode,
|
||||
mode, // possible values: walking, driving, cycling
|
||||
arrivalTime,
|
||||
departureTime,
|
||||
alternatives,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package SuMoC.backend.routing;
|
||||
|
||||
import SuMoC.backend.carta.CartaClient;
|
||||
import SuMoC.backend.routing.dtos.RouteAlternativeDTO;
|
||||
import SuMoC.backend.routing.dtos.RouteAlternativeRequestDTO;
|
||||
import SuMoC.backend.routing.dtos.RouteDTO;
|
||||
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
|
||||
import SuMoC.backend.routing.dtos.RoutingPreferencesDTO;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -17,34 +17,28 @@ import java.util.List;
|
||||
@RequestMapping("/routing/alternative")
|
||||
public class RoutingController {
|
||||
private final RoutingService routingService;
|
||||
private final CartaClient cartaClient;
|
||||
|
||||
@Autowired
|
||||
public RoutingController(RoutingService routingService, CartaClient cartaClient) {
|
||||
public RoutingController(RoutingService routingService) {
|
||||
this.routingService = routingService;
|
||||
this.cartaClient = cartaClient;
|
||||
}
|
||||
|
||||
// TODO operation description + how to handle preferences (optional, if not provided use saved users prefs or default
|
||||
@PostMapping("/request")
|
||||
public ResponseEntity<List<RouteAlternativeDTO>> requestAlternativeRoutes(@Valid @RequestBody RouteAlternativeRequestDTO routeAlternativeRequestDTO) {
|
||||
var direction = cartaClient.getRoute(
|
||||
routeAlternativeRequestDTO.getOrigin(),
|
||||
routeAlternativeRequestDTO.getDestination(),
|
||||
"walking", // mode
|
||||
null, // arrivalTime
|
||||
null, // departureTime
|
||||
1, // alternatives
|
||||
null, // walkingSpeed
|
||||
null, // transferTime
|
||||
null, // accessible
|
||||
null, // parking
|
||||
null, // type
|
||||
null, // range
|
||||
null // location
|
||||
);
|
||||
var dto = new RouteAlternativeDTO();
|
||||
dto.setDirection(direction);
|
||||
return ResponseEntity.ok(List.of(dto));
|
||||
public ResponseEntity<List<RouteDTO>> requestAlternativeRoutes(@Valid @RequestBody RoutingAlternativeRequestDTO routingAlternativeRequestDTO) {
|
||||
RoutingPreferencesDTO preferences = routingAlternativeRequestDTO.getRoutingPreferencesDTO();
|
||||
if (preferences == null) { // Use default preferences if none are provided
|
||||
// TODO we might want to also save users preferences in the future
|
||||
preferences = new RoutingPreferencesDTO(); // use default preferences
|
||||
routingAlternativeRequestDTO.setRoutingPreferencesDTO(preferences);
|
||||
}
|
||||
|
||||
//var routeDTOs = routingService.getAlternativeRoute(routingAlternativeRequestDTO);
|
||||
|
||||
// Mocking response for app development
|
||||
var routeDTOs = List.of(RouteDTO.getMockRouteDTO());
|
||||
|
||||
|
||||
return ResponseEntity.ok(routeDTOs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,47 @@
|
||||
package SuMoC.backend.routing;
|
||||
|
||||
import SuMoC.backend.carta.CartaClient;
|
||||
import SuMoC.backend.routing.dtos.RouteDTO;
|
||||
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class RoutingService {
|
||||
|
||||
private final CartaClient cartaClient;
|
||||
|
||||
@Autowired
|
||||
public RoutingService(CartaClient cartaClient) {
|
||||
this.cartaClient = cartaClient;
|
||||
}
|
||||
|
||||
// // TODO make async for parallel weather calls
|
||||
// private Direction getDirectionFromCarta(RoutingAlternativeRequestDTO requestDTO) {
|
||||
// return cartaClient.getRoute(
|
||||
// requestDTO.getOrigin(),
|
||||
// requestDTO.getDestination(),
|
||||
// "walking", // mode
|
||||
// null, // arrivalTime
|
||||
// null, // departureTime
|
||||
// 1, // alternatives
|
||||
// null, // walkingSpeed
|
||||
// null, // transferTime
|
||||
// null, // accessible
|
||||
// null, // parking
|
||||
// null, // type
|
||||
// null, // range
|
||||
// null // location
|
||||
// );
|
||||
// }
|
||||
|
||||
public List<RouteDTO> getAlternativeRoute(RoutingAlternativeRequestDTO requestDTO) {
|
||||
// TODO make parallel requests for different modes + compare with carta web how they request mode combined travel
|
||||
|
||||
// var dto = getDirectionFromCarta(requestDTO);
|
||||
return new ArrayList<RouteDTO>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import sumoc.backend.carta.client.model.Direction;
|
||||
|
||||
public class RouteAlternativeDTO {
|
||||
private Direction direction;
|
||||
|
||||
// Getters and setters
|
||||
public Direction getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(Direction direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class RouteAlternativeRequestDTO {
|
||||
private String origin; // Lat long
|
||||
private String destination; // Lat long
|
||||
private LocalDateTime arrivalTime;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.annotation.Nullable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "This DTO represents a suggested route as a response to a requested alternative route.")
|
||||
public class RouteDTO {
|
||||
@Schema(description = "The actual address of the start location.")
|
||||
private String startAddress;
|
||||
@Schema(description = "The name of the first stop if the route uses public transport. E.g. \"Essen West\" if the route starts with a footpath to the first train leaving there.")
|
||||
@Nullable
|
||||
private String firstStopName;
|
||||
@Schema(description = "The latitude of the start address.")
|
||||
private double startLat;
|
||||
@Schema(description = "The longitude of the start address.")
|
||||
private double startLon;
|
||||
@Schema(description = "The actual address of the end location.")
|
||||
private String endAddress;
|
||||
@Schema(description = "The name of the last stop if the route uses public transport. E.g. \"Essen Hbf\" if the route ends with a train arriving there (might still contain a footpath afterwards).")
|
||||
@Nullable
|
||||
private String lastStopName;
|
||||
@Schema(description = "The latitude of the end address.")
|
||||
private String endLat;
|
||||
@Schema(description = "The longitude of the end address.")
|
||||
private String endLon;
|
||||
@Schema(description = "The start date and time of the route.")
|
||||
private LocalDateTime startDateTime;
|
||||
@Schema(description = "The end date and time of the route.")
|
||||
private LocalDateTime endDateTime;
|
||||
@Schema(description = "The steps the route consists of.")
|
||||
private List<StepDTO> steps;
|
||||
@Schema(description = "Amount of CO2e savings in gramm compared to a car trip for the same route.")
|
||||
private float co2Savings;
|
||||
@Schema(description = "The temporal difference in minutes compared to the original route the user requested alternatives for.")
|
||||
private float timeDifferenceMinutes;
|
||||
|
||||
/**
|
||||
* Mock method for testing purposes
|
||||
*
|
||||
* @return RouteDto with mock data
|
||||
*/
|
||||
public static RouteDTO getMockRouteDTO() {
|
||||
var dto = new RouteDTO(
|
||||
"Janssenstraße 28a, 45147 Essen, Germany",
|
||||
"Rubensstraße",
|
||||
51.440395,
|
||||
6.984785,
|
||||
"Schützenbahn 70, 45127 Essen, Germany",
|
||||
"Viehhofer Platz",
|
||||
"51.459167",
|
||||
"7.014928",
|
||||
LocalDateTime.now().minusMinutes(30),
|
||||
LocalDateTime.now(),
|
||||
new ArrayList<StepDTO>(),
|
||||
120.5f,
|
||||
+16.3f
|
||||
);
|
||||
dto.steps.add(new StepDTO(
|
||||
Modality.WALK,
|
||||
null,
|
||||
400f
|
||||
));
|
||||
dto.steps.add(new StepDTO(
|
||||
Modality.TRAM,
|
||||
"106",
|
||||
5000f
|
||||
));
|
||||
dto.steps.add(new StepDTO(
|
||||
Modality.WALK,
|
||||
null,
|
||||
300f
|
||||
));
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "This DTO represents a request for alternative routes between an origin and a destination.")
|
||||
public class RoutingAlternativeRequestDTO {
|
||||
@NotNull
|
||||
private String originLat;
|
||||
@NotNull
|
||||
private String originLon;
|
||||
@NotNull
|
||||
private String destinationLat;
|
||||
@NotNull
|
||||
private String destinationLon;
|
||||
@NotNull
|
||||
private LocalDateTime arrivalTime;
|
||||
@NotNull
|
||||
private LocalDateTime departureTime; // We need both times to calculate duration to compare alternatives
|
||||
@Nullable
|
||||
private RoutingPreferencesDTO routingPreferencesDTO;
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This DTO represents the user preferences for routing / alternative route suggestions.
|
||||
* Provides default values for all fields.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(description = "This DTO represents the user preferences for routing / alternative route suggestions.")
|
||||
public class RoutingPreferencesDTO {
|
||||
private boolean preferPhysicalActivity = false;
|
||||
private List<Modality> excludedModalities = List.of();
|
||||
private boolean considerWeatherConditions = true;
|
||||
private List<Modality> modalitiesToConsider = new ArrayList<>(
|
||||
List.of(Modality.WALK, Modality.BIKE, Modality.ESCOOTER, Modality.BUS, Modality.TRAM, Modality.TRAIN)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package SuMoC.backend.routing.dtos;
|
||||
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "A single step within a suggested alternative route.")
|
||||
public class StepDTO {
|
||||
private Modality modality;
|
||||
private String lineNumber;
|
||||
private float distanceMeters;
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package SuMoC.backend.trip;
|
||||
|
||||
public enum Modality {
|
||||
IDLE,
|
||||
WALKING,
|
||||
WALK,
|
||||
BIKE,
|
||||
ESCOOTER,
|
||||
BUS,
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package SuMoC.backend.trip.dtos;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* DTO representing a trip already persisted in the database.
|
||||
*/
|
||||
// TODO refactor to UploadedTripDTO for clarity against RouteDTO
|
||||
@Setter
|
||||
@Getter
|
||||
public class TripDTO {
|
||||
private long tripId;
|
||||
private int userId;
|
||||
@@ -16,7 +22,8 @@ public class TripDTO {
|
||||
private float mobilityScore;
|
||||
private List<TripSegmentDTO> tripSegments;
|
||||
|
||||
public TripDTO() {}
|
||||
public TripDTO() {
|
||||
}
|
||||
|
||||
public TripDTO(int userId, String startPlace, String endPlace, LocalDateTime startTime, LocalDateTime endTime, float mobilityScore, List<TripSegmentDTO> tripSegmentDTOS) {
|
||||
this.userId = userId;
|
||||
@@ -28,67 +35,4 @@ public class TripDTO {
|
||||
this.tripSegments = tripSegmentDTOS;
|
||||
}
|
||||
|
||||
public long getTripId() {
|
||||
return tripId;
|
||||
}
|
||||
|
||||
public void setTripId(long tripId) {
|
||||
this.tripId = tripId;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getStartPlace() {
|
||||
return startPlace;
|
||||
}
|
||||
|
||||
public void setStartPlace(String startPlace) {
|
||||
this.startPlace = startPlace;
|
||||
}
|
||||
|
||||
public String getEndPlace() {
|
||||
return endPlace;
|
||||
}
|
||||
|
||||
public void setEndPlace(String endPlace) {
|
||||
this.endPlace = endPlace;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(LocalDateTime startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public LocalDateTime getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(LocalDateTime endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public float getMobilityScore() {
|
||||
return mobilityScore;
|
||||
}
|
||||
|
||||
public void setMobilityScore(float mobilityScore) {
|
||||
this.mobilityScore = mobilityScore;
|
||||
}
|
||||
|
||||
public List<TripSegmentDTO> getTripSegments() {
|
||||
return tripSegments;
|
||||
}
|
||||
|
||||
public void setTripSegments(List<TripSegmentDTO> tripSegments) {
|
||||
this.tripSegments = tripSegments;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user