-
Notifications
You must be signed in to change notification settings - Fork 0
Task/add sensor metadata #31
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
Merged
Merged
Changes from 22 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
0cdd9fe
Include db changelog v3
SelahattinSert cc2ab2d
Add sensor_metadata liquibase changelog
SelahattinSert 920ae1b
Add sensor entities
SelahattinSert e91bb23
Add SensorType enum
SelahattinSert a4f0f67
Add sensor exceptions
SelahattinSert 25acda8
Add sensor repositories
SelahattinSert 80e105d
Add sensor service
SelahattinSert 167dd8b
Add sensor service implementations
SelahattinSert 8e23d30
Add sensor dto
SelahattinSert 2ee497a
Add sensor response
SelahattinSert 9f3e26b
Add sensor dto converter
SelahattinSert ecc1cda
Add sensor exception handler methods
SelahattinSert 3ae6b1a
Add sensor REST controllers
SelahattinSert ae5d91b
Include changelog v3
SelahattinSert 0b2c00d
Remove redundant exception handling
SelahattinSert 5012b03
Refactor service methods
SelahattinSert 37e3f5a
Refactor repository
SelahattinSert ed39154
Add enum explanation
SelahattinSert 973954c
Add sensors list to camera entity
SelahattinSert 0a42b37
Add toString annotation
SelahattinSert 7298ae8
Add toString annotation
SelahattinSert 15483c0
Refactor conversion methods
SelahattinSert 71eceac
Remove redundant path variable
SelahattinSert 6531381
Merge branch 'master' into 'task/add-sensor-metadata' to include CI w…
SelahattinSert 961d86c
Include db changelog v3
SelahattinSert beb2aa8
Merge branch 'master' into 'task/add-sensor-metadata' to include CI w…
SelahattinSert 3debae9
Fix test case issue
SelahattinSert d13a3cc
Utilize path variable camera id
SelahattinSert 37aa546
Add list of sensors to camera response
SelahattinSert 058b0f5
Refactor sensor methods
SelahattinSert 9f013e5
Refactor sensor receive method
SelahattinSert 38f15be
Add sensor dto converter unit test
SelahattinSert 8bff631
Add light sensor unit and integration tests
SelahattinSert 33d39d6
Add sensor dto validation method
SelahattinSert 402a178
Add test cases for invalid data
SelahattinSert 914a5c1
Fix sensor test methods
SelahattinSert e9dd43a
Remove unused import
SelahattinSert fe79fcf
Add new test cases
SelahattinSert 7529618
Fix test methods
SelahattinSert 01d7d73
Add motion and temperature sensor controller tests
SelahattinSert 131ee0d
Add motion and temperature sensor repository tests
SelahattinSert f297971
Add motion and temperature sensor service tests
SelahattinSert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/onboarding/camera/cameraonboarding/controller/LightSensorController.java
This file contains hidden or 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,71 @@ | ||
| package com.onboarding.camera.cameraonboarding.controller; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.converter.SensorDtoConverter; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorDto; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorResponse; | ||
| import com.onboarding.camera.cameraonboarding.entity.LightSensor; | ||
| import com.onboarding.camera.cameraonboarding.service.impl.LightSensorService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping("${api.version}/camera/{cameraId}/sensor/light") | ||
| @RequiredArgsConstructor | ||
| public class LightSensorController { | ||
|
|
||
| private final LightSensorService lightSensorService; | ||
|
|
||
| private final SensorDtoConverter sensorDtoConverter; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<SensorResponse> addLightSensor( | ||
| @PathVariable UUID cameraId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| LightSensor sensorMetadata = sensorDtoConverter.toLightEntity(sensorDto); | ||
| LightSensor savedSensor = lightSensorService.handleCreateSensor(cameraId, sensorMetadata); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(savedSensor); | ||
|
|
||
| return new ResponseEntity<>(sensorResponse, HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<LightSensor>> getLightSensors( | ||
| @PathVariable UUID cameraId) { | ||
|
|
||
| List<LightSensor> sensors = lightSensorService.handleGetSensorsByCameraId(cameraId); | ||
| return ResponseEntity.ok(sensors); | ||
| } | ||
|
|
||
| @PutMapping("/{sensorId}") | ||
| public ResponseEntity<SensorResponse> updateLightSensor( | ||
| @PathVariable UUID sensorId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| LightSensor sensorMetadata = sensorDtoConverter.toLightEntity(sensorDto); | ||
| LightSensor updatedSensor = lightSensorService.handleUpdateSensor(sensorId, sensorMetadata); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(updatedSensor); | ||
| return ResponseEntity.ok(sensorResponse); | ||
| } | ||
|
|
||
| @DeleteMapping("/{sensorId}") | ||
| public ResponseEntity<Void> deleteLightSensor( | ||
| @PathVariable UUID sensorId) { | ||
|
|
||
| lightSensorService.handleDeleteSensor(sensorId); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
src/main/java/com/onboarding/camera/cameraonboarding/controller/MotionSensorController.java
This file contains hidden or 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,71 @@ | ||
| package com.onboarding.camera.cameraonboarding.controller; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.converter.SensorDtoConverter; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorDto; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorResponse; | ||
| import com.onboarding.camera.cameraonboarding.entity.MotionSensor; | ||
| import com.onboarding.camera.cameraonboarding.service.impl.MotionSensorService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping("${api.version}/camera/{cameraId}/sensor/motion") | ||
ozgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @RequiredArgsConstructor | ||
| public class MotionSensorController { | ||
|
|
||
| private final MotionSensorService motionSensorService; | ||
|
|
||
| private final SensorDtoConverter sensorDtoConverter; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<SensorResponse> addMotionSensor( | ||
| @PathVariable UUID cameraId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| MotionSensor motionSensor = sensorDtoConverter.toMotionEntity(sensorDto); | ||
| MotionSensor savedSensor = motionSensorService.handleCreateSensor(cameraId, motionSensor); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(savedSensor); | ||
|
|
||
| return new ResponseEntity<>(sensorResponse, HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<MotionSensor>> getMotionSensors( | ||
| @PathVariable UUID cameraId) { | ||
|
|
||
| List<MotionSensor> sensors = motionSensorService.handleGetSensorsByCameraId(cameraId); | ||
| return ResponseEntity.ok(sensors); | ||
| } | ||
|
|
||
| @PutMapping("/{sensorId}") | ||
| public ResponseEntity<SensorResponse> updateMotionSensor( | ||
| @PathVariable UUID sensorId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| MotionSensor motionSensor = sensorDtoConverter.toMotionEntity(sensorDto); | ||
| MotionSensor updatedSensor = motionSensorService.handleUpdateSensor(sensorId, motionSensor); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(updatedSensor); | ||
| return ResponseEntity.ok(sensorResponse); | ||
| } | ||
|
|
||
| @DeleteMapping("/{sensorId}") | ||
| public ResponseEntity<Void> deleteMotionSensor( | ||
| @PathVariable UUID sensorId) { | ||
|
|
||
| motionSensorService.handleDeleteSensor(sensorId); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
70 changes: 70 additions & 0 deletions
70
...n/java/com/onboarding/camera/cameraonboarding/controller/TemperatureSensorController.java
This file contains hidden or 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,70 @@ | ||
| package com.onboarding.camera.cameraonboarding.controller; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.converter.SensorDtoConverter; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorDto; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorResponse; | ||
| import com.onboarding.camera.cameraonboarding.entity.TemperatureSensor; | ||
| import com.onboarding.camera.cameraonboarding.service.impl.TemperatureSensorService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping("${api.version}/camera/{cameraId}/sensor/temperature") | ||
ozgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @RequiredArgsConstructor | ||
| public class TemperatureSensorController { | ||
|
|
||
| private final TemperatureSensorService temperatureSensorService; | ||
|
|
||
| private final SensorDtoConverter sensorDtoConverter; | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<SensorResponse> addTemperatureSensor( | ||
| @PathVariable UUID cameraId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| TemperatureSensor sensorMetadata = sensorDtoConverter.toTemperatureEntity(sensorDto); | ||
| TemperatureSensor savedSensor = temperatureSensorService.handleCreateSensor(cameraId, sensorMetadata); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(savedSensor); | ||
| return new ResponseEntity<>(sensorResponse, HttpStatus.CREATED); | ||
| } | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<List<TemperatureSensor>> getTemperatureSensors( | ||
| @PathVariable UUID cameraId) { | ||
|
|
||
| List<TemperatureSensor> sensors = temperatureSensorService.handleGetSensorsByCameraId(cameraId); | ||
| return ResponseEntity.ok(sensors); | ||
| } | ||
|
|
||
| @PutMapping("/{sensorId}") | ||
| public ResponseEntity<SensorResponse> updateTemperatureSensor( | ||
| @PathVariable UUID sensorId, | ||
| @Valid @RequestBody SensorDto sensorDto) { | ||
|
|
||
| TemperatureSensor sensorMetadata = sensorDtoConverter.toTemperatureEntity(sensorDto); | ||
| TemperatureSensor updatedSensor = temperatureSensorService.handleUpdateSensor(sensorId, sensorMetadata); | ||
| SensorResponse sensorResponse = sensorDtoConverter.toSensorResponse(updatedSensor); | ||
| return ResponseEntity.ok(sensorResponse); | ||
| } | ||
|
|
||
| @DeleteMapping("/{sensorId}") | ||
| public ResponseEntity<Void> deleteTemperatureSensor( | ||
| @PathVariable UUID sensorId) { | ||
|
|
||
| temperatureSensorService.handleDeleteSensor(sensorId); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
src/main/java/com/onboarding/camera/cameraonboarding/converter/SensorDtoConverter.java
This file contains hidden or 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,64 @@ | ||
| package com.onboarding.camera.cameraonboarding.converter; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.dto.SensorDto; | ||
| import com.onboarding.camera.cameraonboarding.dto.SensorResponse; | ||
| import com.onboarding.camera.cameraonboarding.entity.LightSensor; | ||
| import com.onboarding.camera.cameraonboarding.entity.MotionSensor; | ||
| import com.onboarding.camera.cameraonboarding.entity.Sensor; | ||
| import com.onboarding.camera.cameraonboarding.entity.TemperatureSensor; | ||
| import com.onboarding.camera.cameraonboarding.enums.SensorType; | ||
| import com.onboarding.camera.cameraonboarding.exception.SensorMismatchException; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class SensorDtoConverter { | ||
|
|
||
| public MotionSensor toMotionEntity(SensorDto sensorDto) { | ||
| if (sensorDto.getSensorType() != SensorType.MOTION) { | ||
| throw new SensorMismatchException("Invalid sensor type for MotionSensor"); | ||
| } | ||
|
|
||
| MotionSensor sensorMetadata = new MotionSensor(); | ||
| sensorMetadata.setName(sensorDto.getName()); | ||
| sensorMetadata.setVersion(sensorDto.getVersion()); | ||
| sensorMetadata.setSensorType(sensorDto.getSensorType()); | ||
| sensorMetadata.setData(sensorDto.getData()); | ||
| return sensorMetadata; | ||
| } | ||
|
|
||
| public LightSensor toLightEntity(SensorDto sensorDto) { | ||
| if (sensorDto.getSensorType() != SensorType.LIGHT) { | ||
| throw new SensorMismatchException("Invalid sensor type for LightSensor"); | ||
| } | ||
|
|
||
| LightSensor sensorMetadata = new LightSensor(); | ||
| sensorMetadata.setName(sensorDto.getName()); | ||
| sensorMetadata.setVersion(sensorDto.getVersion()); | ||
| sensorMetadata.setSensorType(sensorDto.getSensorType()); | ||
| sensorMetadata.setData(sensorDto.getData()); | ||
| return sensorMetadata; | ||
| } | ||
|
|
||
| public TemperatureSensor toTemperatureEntity(SensorDto sensorDto) { | ||
| if (sensorDto.getSensorType() != SensorType.TEMPERATURE) { | ||
| throw new SensorMismatchException("Invalid sensor type for TemperatureSensor"); | ||
| } | ||
|
|
||
| TemperatureSensor sensorMetadata = new TemperatureSensor(); | ||
| sensorMetadata.setName(sensorDto.getName()); | ||
| sensorMetadata.setVersion(sensorDto.getVersion()); | ||
| sensorMetadata.setSensorType(sensorDto.getSensorType()); | ||
| sensorMetadata.setData(sensorDto.getData()); | ||
| return sensorMetadata; | ||
| } | ||
|
|
||
| public SensorResponse toSensorResponse(Sensor sensor) { | ||
| SensorResponse response = new SensorResponse(); | ||
| response.setId(sensor.getId()); | ||
| response.setName(sensor.getName()); | ||
| response.setVersion(sensor.getVersion()); | ||
| response.setSensorType(sensor.getSensorType()); | ||
| response.setData(sensor.getData()); | ||
| return response; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/onboarding/camera/cameraonboarding/dto/SensorDto.java
This file contains hidden or 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,30 @@ | ||
| package com.onboarding.camera.cameraonboarding.dto; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.enums.SensorType; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.ToString; | ||
|
|
||
| @Data | ||
| @ToString | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class SensorDto { | ||
ozgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @NotBlank(message = "Sensor name cannot be blank") | ||
| @Size(min = 2, max = 100, message = "Sensor name should be between 2 and 100 characters") | ||
| private String name; | ||
|
|
||
| @NotBlank(message = "Version cannot be blank") | ||
| @Size(min = 2, max = 50, message = "Version should be between 2 and 50 characters") | ||
| private String version; | ||
|
|
||
| @NotNull(message = "Sensor type cannot be null") | ||
| private SensorType sensorType; | ||
|
|
||
| private String data; | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
src/main/java/com/onboarding/camera/cameraonboarding/dto/SensorResponse.java
This file contains hidden or 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,15 @@ | ||
| package com.onboarding.camera.cameraonboarding.dto; | ||
|
|
||
| import com.onboarding.camera.cameraonboarding.enums.SensorType; | ||
| import lombok.Data; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Data | ||
| public class SensorResponse { | ||
| private UUID id; | ||
| private String name; | ||
| private String version; | ||
| private SensorType sensorType; | ||
| private String data; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.