refactor to use Instant instead of LocalDateTime
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -6,8 +6,7 @@ import sumoc.backend.carta.client.api.CartaApi;
|
||||
import sumoc.backend.carta.client.api.MapApi;
|
||||
import sumoc.backend.carta.client.model.Direction;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Service
|
||||
@@ -40,8 +39,8 @@ public class CartaClient {
|
||||
String origin,
|
||||
String destination,
|
||||
String mode,
|
||||
LocalDateTime arrivalTime,
|
||||
LocalDateTime departureTime,
|
||||
Instant arrivalTime,
|
||||
Instant departureTime,
|
||||
Integer alternatives,
|
||||
Double walkingSpeed,
|
||||
Integer transferTime,
|
||||
@@ -54,8 +53,8 @@ public class CartaClient {
|
||||
origin,
|
||||
destination,
|
||||
mode.toLowerCase(), // possible values: walking, driving, cycling
|
||||
arrivalTime.toEpochSecond(ZoneOffset.UTC),
|
||||
departureTime.toEpochSecond(ZoneOffset.UTC),
|
||||
arrivalTime.getEpochSecond(),
|
||||
departureTime.getEpochSecond(),
|
||||
alternatives,
|
||||
walkingSpeed,
|
||||
transferTime,
|
||||
|
||||
@@ -8,7 +8,8 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -36,9 +37,9 @@ public class RouteDTO {
|
||||
@Schema(description = "The longitude of the end address.")
|
||||
private double endLon;
|
||||
@Schema(description = "The start date and time of the route.")
|
||||
private LocalDateTime startDateTime;
|
||||
private Instant startDateTime;
|
||||
@Schema(description = "The end date and time of the route.")
|
||||
private LocalDateTime endDateTime;
|
||||
private Instant 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.")
|
||||
@@ -46,7 +47,7 @@ public class RouteDTO {
|
||||
@Schema(description = "The temporal difference in minutes compared to the original route the user requested alternatives for.")
|
||||
private double timeDifferenceSeconds;
|
||||
|
||||
public RouteDTO(AddressDTO startAddress, @Nullable String firstStopName, double startLat, double startLon, AddressDTO endAddress, @Nullable String lastStopName, double endLat, double endLon, LocalDateTime startDateTime, LocalDateTime endDateTime, List<StepDTO> steps, double co2Savings, double timeDifferenceSeconds) {
|
||||
public RouteDTO(AddressDTO startAddress, @Nullable String firstStopName, double startLat, double startLon, AddressDTO endAddress, @Nullable String lastStopName, double endLat, double endLon, Instant startDateTime, Instant endDateTime, List<StepDTO> steps, double co2Savings, double timeDifferenceSeconds) {
|
||||
this.startAddress = startAddress;
|
||||
this.firstStopName = firstStopName;
|
||||
this.startLat = startLat;
|
||||
@@ -101,8 +102,8 @@ public class RouteDTO {
|
||||
"Viehhofer Platz",
|
||||
51.459167,
|
||||
7.014928,
|
||||
LocalDateTime.now().minusMinutes(30),
|
||||
LocalDateTime.now(),
|
||||
Instant.now().minus(Duration.ofMinutes(30)),
|
||||
Instant.now(),
|
||||
new ArrayList<StepDTO>(),
|
||||
120.5f,
|
||||
+16.3f
|
||||
|
||||
@@ -6,7 +6,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -21,9 +21,9 @@ public class RoutingAlternativeRequestDTO {
|
||||
@NotNull
|
||||
private Double destinationLon;
|
||||
@NotNull
|
||||
private LocalDateTime arrivalTime;
|
||||
private Instant arrivalTime;
|
||||
@NotNull
|
||||
private LocalDateTime departureTime; // We need both times to calculate duration to compare alternatives
|
||||
private Instant departureTime; // We need both times to calculate duration to compare alternatives
|
||||
@Nullable
|
||||
private RoutingPreferencesDTO routingPreferencesDTO;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DevTripSeeder implements CommandLineRunner {
|
||||
userRepository.findAll().forEach(user -> {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
NewTripDTO newTrip = TripFactory.randomNewTripDTO(
|
||||
java.time.LocalDateTime.now().minusDays((long) (Math.random() * 30))
|
||||
java.time.Instant.now().minus(java.time.Duration.ofDays((long) (Math.random() * 30)))
|
||||
);
|
||||
tripService.addTrip(user, newTrip);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ import SuMoC.backend.trip.dtos.NewTripDTO;
|
||||
import SuMoC.backend.trip.dtos.NewTripSegmentDTO;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@@ -27,7 +28,7 @@ public class TripFactory {
|
||||
* take 2 hours in total, and have random start and end places from a predefined list of NRW cities.
|
||||
* So data is not really realistic.
|
||||
*/
|
||||
public static NewTripDTO randomNewTripDTO(LocalDateTime startTime) {
|
||||
public static NewTripDTO randomNewTripDTO(Instant startTime) {
|
||||
String startPlace = NRW_CITIES.get(ThreadLocalRandom.current().nextInt(NRW_CITIES.size()));
|
||||
String endPlace = NRW_CITIES.get(ThreadLocalRandom.current().nextInt(NRW_CITIES.size()));
|
||||
while (endPlace.equals(startPlace)) {
|
||||
@@ -42,7 +43,7 @@ public class TripFactory {
|
||||
.build(),
|
||||
NewTripSegmentDTO.builder()
|
||||
.modality(randomModality())
|
||||
.startTime(startTime.plusMinutes(60))
|
||||
.startTime(startTime.plus(Duration.ofMinutes(60)))
|
||||
.distanceMeters(ThreadLocalRandom.current().nextFloat() * 10000)
|
||||
.build()
|
||||
);
|
||||
@@ -56,7 +57,7 @@ public class TripFactory {
|
||||
.endLongitude(6.800951430299369)
|
||||
.co2Emissions(100.0)
|
||||
.startTime(startTime)
|
||||
.endTime(startTime.plusMinutes(120))
|
||||
.endTime(startTime.plus(Duration.ofMinutes(120)))
|
||||
.mobilityScore(ThreadLocalRandom.current().nextFloat() * 100)
|
||||
.tripSegments(segments)
|
||||
.build();
|
||||
|
||||
@@ -5,7 +5,7 @@ import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -27,8 +27,8 @@ public class NewTripDTO {
|
||||
private String endPlace;
|
||||
private double endLatitude;
|
||||
private double endLongitude;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private Instant startTime;
|
||||
private Instant endTime;
|
||||
private double mobilityScore;
|
||||
private double co2Emissions;
|
||||
@NotNull
|
||||
|
||||
@@ -3,7 +3,7 @@ package SuMoC.backend.trip.dtos;
|
||||
import SuMoC.backend.trip.Modality;
|
||||
import lombok.Builder;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* DTO representing a trip segment submitted from the App which is not yet persisted in the database.
|
||||
@@ -11,13 +11,13 @@ import java.time.LocalDateTime;
|
||||
@Builder
|
||||
public class NewTripSegmentDTO {
|
||||
private Modality modality;
|
||||
private LocalDateTime startTime;
|
||||
private Instant startTime;
|
||||
private float distanceMeters;
|
||||
|
||||
public NewTripSegmentDTO() {
|
||||
}
|
||||
|
||||
public NewTripSegmentDTO(Modality modality, LocalDateTime startTime, float distanceMeters) {
|
||||
public NewTripSegmentDTO(Modality modality, Instant startTime, float distanceMeters) {
|
||||
this.modality = modality;
|
||||
this.startTime = startTime;
|
||||
this.distanceMeters = distanceMeters;
|
||||
@@ -27,7 +27,7 @@ public class NewTripSegmentDTO {
|
||||
return modality;
|
||||
}
|
||||
|
||||
public LocalDateTime getStartTime() {
|
||||
public Instant getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "Represents a trip uploaded to the backend by a user that is already stored in the DB.")
|
||||
@@ -23,8 +23,8 @@ public class TripDTO {
|
||||
private String endPlace;
|
||||
private double endLatitude;
|
||||
private double endLongitude;
|
||||
private LocalDateTime startTime;
|
||||
private LocalDateTime endTime;
|
||||
private Instant startTime;
|
||||
private Instant endTime;
|
||||
private double mobilityScore;
|
||||
private double co2Emissions;
|
||||
private List<TripSegmentDTO> tripSegments;
|
||||
|
||||
@@ -4,7 +4,7 @@ import SuMoC.backend.trip.Modality;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* DTO representing a trip segment already persisted in the database.
|
||||
@@ -15,12 +15,13 @@ public class TripSegmentDTO {
|
||||
private long tripSegmentId;
|
||||
private long tripId;
|
||||
private Modality modality;
|
||||
private LocalDateTime startTime;
|
||||
private Instant startTime;
|
||||
private float distanceMeters;
|
||||
|
||||
public TripSegmentDTO() {}
|
||||
public TripSegmentDTO() {
|
||||
}
|
||||
|
||||
public TripSegmentDTO(long tripSegmentId, long tripId, Modality modality, LocalDateTime startTime, float distanceMeters) {
|
||||
public TripSegmentDTO(long tripSegmentId, long tripId, Modality modality, Instant startTime, float distanceMeters) {
|
||||
this.tripSegmentId = tripSegmentId;
|
||||
this.tripId = tripId;
|
||||
this.modality = modality;
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -46,10 +46,10 @@ public class Trip {
|
||||
private double endLongitude;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime startTime;
|
||||
private Instant startTime;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime endTime;
|
||||
private Instant endTime;
|
||||
|
||||
/**
|
||||
* Mobilityscore for the trip.
|
||||
|
||||
@@ -6,7 +6,7 @@ import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@@ -26,7 +26,7 @@ public class TripSegment {
|
||||
private Modality modality;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime startTime;
|
||||
private Instant startTime;
|
||||
|
||||
/**
|
||||
* Distance of the segment in meters.
|
||||
@@ -37,7 +37,7 @@ public class TripSegment {
|
||||
public TripSegment() {
|
||||
}
|
||||
|
||||
public TripSegment(Long id, Trip trip, Modality modality, LocalDateTime startTime, Long distanceMeters) {
|
||||
public TripSegment(Long id, Trip trip, Modality modality, Instant startTime, Long distanceMeters) {
|
||||
this.id = id;
|
||||
this.trip = trip;
|
||||
this.modality = modality;
|
||||
|
||||
@@ -2,7 +2,7 @@ package SuMoC.backend.user.dtos;
|
||||
|
||||
import SuMoC.backend.user.enums.FriendShipStatus;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* DTO for all friendships of a user.
|
||||
@@ -16,12 +16,12 @@ public class FriendshipDTO {
|
||||
private Long userId;
|
||||
private MinimalUserDTO friend;
|
||||
private FriendShipStatus status;
|
||||
private LocalDateTime createdAt;
|
||||
private Instant createdAt;
|
||||
|
||||
public FriendshipDTO() {
|
||||
}
|
||||
|
||||
public FriendshipDTO(Long friendshipId, Long userId, MinimalUserDTO friend, FriendShipStatus status, LocalDateTime createdAt) {
|
||||
public FriendshipDTO(Long friendshipId, Long userId, MinimalUserDTO friend, FriendShipStatus status, Instant createdAt) {
|
||||
this.friendshipId = friendshipId;
|
||||
this.userId = userId;
|
||||
this.friend = friend;
|
||||
@@ -61,11 +61,11 @@ public class FriendshipDTO {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
public Instant getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
public void setCreatedAt(Instant createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import SuMoC.backend.user.enums.FriendShipStatus;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* For explanation of statuses, also see "getFriendships" in UserController.
|
||||
@@ -37,13 +37,13 @@ public class Friendship {
|
||||
private FriendShipStatus status;
|
||||
|
||||
@Column(nullable = false)
|
||||
private LocalDateTime createdAt;
|
||||
private Instant createdAt;
|
||||
|
||||
public Friendship(User user, User friend, FriendShipStatus status) {
|
||||
this.user = user;
|
||||
this.friend = friend;
|
||||
this.status = status;
|
||||
this.createdAt = LocalDateTime.now();
|
||||
this.createdAt = Instant.now();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user