diff --git a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/InMemoryMeasurementRepository.java b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/InMemoryMeasurementRepository.java deleted file mode 100644 index 5ca1d0d..0000000 --- a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/InMemoryMeasurementRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -package it.mulders.traqqr.api.measurements; - -import it.mulders.traqqr.domain.measurements.Measurement; -import it.mulders.traqqr.domain.measurements.MeasurementRepository; -import it.mulders.traqqr.domain.vehicles.Vehicle; -import jakarta.enterprise.context.ApplicationScoped; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -@ApplicationScoped -public class InMemoryMeasurementRepository implements MeasurementRepository { - private final Set measurements = Collections.synchronizedSet(new HashSet<>()); - - @Override - public void save(Measurement measurement) { - measurements.add(measurement); - } - - @Override - public Collection findByVehicle(Vehicle vehicle) { - return measurements.stream() - .filter(measurement -> measurement.vehicle().equals(vehicle)) - .collect(Collectors.toList()); - } -} diff --git a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementDto.java b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementDto.java deleted file mode 100644 index 980f140..0000000 --- a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementDto.java +++ /dev/null @@ -1,75 +0,0 @@ -package it.mulders.traqqr.api.measurements; - -import java.time.OffsetDateTime; - -public class MeasurementDto { - private OffsetDateTime timestamp; - private int odometer; - private BatteryDto battery; - private LocationDto location; - - public OffsetDateTime getTimestamp() { - return timestamp; - } - - public void setTimestamp(OffsetDateTime timestamp) { - this.timestamp = timestamp; - } - - public int getOdometer() { - return odometer; - } - - public void setOdometer(int odometer) { - this.odometer = odometer; - } - - public BatteryDto getBattery() { - return battery; - } - - public void setBattery(BatteryDto battery) { - this.battery = battery; - } - - public LocationDto getLocation() { - return location; - } - - public void setLocation(LocationDto location) { - this.location = location; - } - - public static class BatteryDto { - private byte soc; - - public byte getSoc() { - return soc; - } - - public void setSoc(byte soc) { - this.soc = soc; - } - } - - public static class LocationDto { - private double lat; - private double lon; - - public double getLat() { - return lat; - } - - public void setLat(double lat) { - this.lat = lat; - } - - public double getLon() { - return lon; - } - - public void setLon(double lon) { - this.lon = lon; - } - } -} diff --git a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementMapper.java b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementMapper.java index e102a70..5bc6628 100644 --- a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementMapper.java +++ b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementMapper.java @@ -1,5 +1,6 @@ package it.mulders.traqqr.api.measurements; +import it.mulders.traqqr.api.measurements.dto.MeasurementDto; import it.mulders.traqqr.domain.measurements.Measurement; import it.mulders.traqqr.domain.vehicles.Vehicle; diff --git a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java index 8673def..6113fc2 100644 --- a/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java +++ b/app/adapters/api/src/main/java/it/mulders/traqqr/api/measurements/MeasurementResource.java @@ -1,5 +1,6 @@ package it.mulders.traqqr.api.measurements; +import it.mulders.traqqr.api.measurements.dto.MeasurementDto; import it.mulders.traqqr.domain.measurements.MeasurementRepository; import it.mulders.traqqr.domain.vehicles.Authorisation; import it.mulders.traqqr.domain.vehicles.VehicleRepository; diff --git a/app/adapters/api/src/test/java/it/mulders/traqqr/api/measurements/MeasurementResourceTest.java b/app/adapters/api/src/test/java/it/mulders/traqqr/api/measurements/MeasurementResourceTest.java index 91f63e0..c453a6e 100644 --- a/app/adapters/api/src/test/java/it/mulders/traqqr/api/measurements/MeasurementResourceTest.java +++ b/app/adapters/api/src/test/java/it/mulders/traqqr/api/measurements/MeasurementResourceTest.java @@ -1,5 +1,6 @@ package it.mulders.traqqr.api.measurements; +import it.mulders.traqqr.api.measurements.dto.MeasurementDto; import it.mulders.traqqr.domain.vehicles.Authorisation; import it.mulders.traqqr.domain.vehicles.Vehicle; import it.mulders.traqqr.mem.measurements.InMemoryMeasurementRepository; @@ -34,16 +35,12 @@ public void testRegisterMeasurement_Success() { var vehicle = new Vehicle("code123", "description", "ownerId", Set.of(Authorisation.fromInput("hashedKey123"))); vehicleRepository.save(vehicle); - var measurementDto = new MeasurementDto(); - measurementDto.setTimestamp(OffsetDateTime.now()); - measurementDto.setOdometer(1000); - var batteryDto = new MeasurementDto.BatteryDto(); - batteryDto.setSoc((byte) 80); - measurementDto.setBattery(batteryDto); - var locationDto = new MeasurementDto.LocationDto(); - locationDto.setLat(52.0); - locationDto.setLon(4.0); - measurementDto.setLocation(locationDto); + var measurementDto = new MeasurementDto( + OffsetDateTime.now(), + 1000, + new MeasurementDto.BatteryDto((byte) 80), + new MeasurementDto.LocationDto(52.0, 4.0) + ); var headers = new ResteasyHttpHeaders( new MultivaluedHashMap<>(Map.of("X-VEHICLE-API-KEY", "hashedKey123")) @@ -56,16 +53,12 @@ public void testRegisterMeasurement_Success() { @Test public void testRegisterMeasurement_VehicleNotFound() { - var measurementDto = new MeasurementDto(); - measurementDto.setTimestamp(OffsetDateTime.now()); - measurementDto.setOdometer(1000); - var batteryDto = new MeasurementDto.BatteryDto(); - batteryDto.setSoc((byte) 80); - measurementDto.setBattery(batteryDto); - var locationDto = new MeasurementDto.LocationDto(); - locationDto.setLat(52.0); - locationDto.setLon(4.0); - measurementDto.setLocation(locationDto); + var measurementDto = new MeasurementDto( + OffsetDateTime.now(), + 1000, + new MeasurementDto.BatteryDto((byte) 80), + new MeasurementDto.LocationDto(52.0, 4.0) + ); var headers = new ResteasyHttpHeaders( new MultivaluedHashMap<>(Map.of("X-VEHICLE-API-KEY", "hashedKey123")) @@ -80,16 +73,12 @@ public void testRegisterMeasurement_Unauthorized() { var vehicle = new Vehicle("code123", "description", "ownerId", null); vehicleRepository.save(vehicle); - var measurementDto = new MeasurementDto(); - measurementDto.setTimestamp(OffsetDateTime.now()); - measurementDto.setOdometer(1000); - var batteryDto = new MeasurementDto.BatteryDto(); - batteryDto.setSoc((byte) 80); - measurementDto.setBattery(batteryDto); - var locationDto = new MeasurementDto.LocationDto(); - locationDto.setLat(52.0); - locationDto.setLon(4.0); - measurementDto.setLocation(locationDto); + var measurementDto = new MeasurementDto( + OffsetDateTime.now(), + 1000, + new MeasurementDto.BatteryDto((byte) 80), + new MeasurementDto.LocationDto(52.0, 4.0) + ); var headers = new ResteasyHttpHeaders( new MultivaluedHashMap<>(Map.of("X-VEHICLE-API-KEY", "invalidKey"))