feat: Temperature Sensor + removeSensor
This commit is contained in:
parent
a5cff9cf7b
commit
f98e6425be
3 changed files with 46 additions and 5 deletions
|
@ -33,4 +33,9 @@ public class LightSensorController {
|
||||||
return currentMaxId++;
|
return currentMaxId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Float removeSensor(@PathVariable("id") Integer id) {
|
||||||
|
return sensorValues.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package fr.insa.arm.TemperatureSensorService.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/temperatureSensor")
|
||||||
|
public class TemperatureSensorController {
|
||||||
|
|
||||||
|
private final Map<Integer, Float> sensorValues = new HashMap<>();
|
||||||
|
private int currentMaxId = 0;
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Float getSensorValue(@PathVariable("id") Integer id) {
|
||||||
|
return sensorValues.getOrDefault(id, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public Float setSensorValue(@PathVariable("id") Integer id, @RequestBody Float value) {
|
||||||
|
return sensorValues.replace(id, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/")
|
||||||
|
public int addSensor() {
|
||||||
|
sensorValues.put(currentMaxId, null);
|
||||||
|
return currentMaxId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Float removeSensor(@PathVariable("id") Integer id) {
|
||||||
|
return sensorValues.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +0,0 @@
|
||||||
package fr.insa.arm.TemperatureSensorService.model;
|
|
||||||
|
|
||||||
public class TemperatureSensor {
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in a new issue