feat: REST urls for Rooms

This commit is contained in:
Jean-Remy Hok 2022-01-11 16:24:18 +01:00
parent fad6fdc7c1
commit 0acfba2520
2 changed files with 33 additions and 33 deletions

View file

@ -15,39 +15,39 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/rooms") @RequestMapping("/rooms")
public class RoomsServiceController { public class RoomsServiceController {
private INSA rooms = new INSA(); private final INSA rooms = new INSA();
@GetMapping("/roomsManagement") @GetMapping("/")
public ArrayList<Integer> getIds() { public ArrayList<Integer> getIds() {
return rooms.getIds(); return rooms.getIds();
} }
@PostMapping("/roomsManagement/{name}") @PostMapping("/")
public int addRoom(@PathVariable("name") String name) { public int addRoom(@RequestBody String name) {
return rooms.addRoom(name); return rooms.addRoom(name);
} }
@DeleteMapping("/roomsManagement/{id}") @DeleteMapping("/{id}")
public Room removeRoom(@PathVariable("id") int id) { public Room removeRoom(@PathVariable("id") int id) {
return rooms.removeRoom(id); return rooms.removeRoom(id);
} }
@GetMapping("/roomsManagement/{id}") @GetMapping("/{id}")
public String getRoomName(@PathVariable("id") int id) { public String getRoomName(@PathVariable("id") int id) {
return rooms.getRoomName(id); return rooms.getRoomName(id);
} }
@PostMapping("/devicesManagement/{id}") @PostMapping("/{id}/devices")
public boolean affectDevice(@PathVariable("id") int idRoom, @RequestParam String type, @RequestBody Integer idDevice) { public boolean affectDevice(@PathVariable("id") int idRoom, @RequestParam String type, @RequestBody Integer idDevice) {
return rooms.affectDevice(idRoom, type, idDevice); return rooms.affectDevice(idRoom, type, idDevice);
} }
@DeleteMapping("/devicesManagement/{id}") @DeleteMapping("/{id}/devices")
public boolean removeDevice(@PathVariable("id") int idRoom, @RequestParam String type, @RequestBody Integer idDevice) { public boolean removeDevice(@PathVariable("id") int idRoom, @RequestParam String type, @RequestBody Integer idDevice) {
return rooms.removeDevice(idRoom, type, idDevice); return rooms.removeDevice(idRoom, type, idDevice);
} }
@GetMapping("/devicesManagement/{id}") @GetMapping("/{id}/devices")
public ArrayList<Integer> getIdsDevice(@PathVariable("id") int idRoom, @RequestParam String type) { public ArrayList<Integer> getIdsDevice(@PathVariable("id") int idRoom, @RequestParam String type) {
return rooms.getIdsDevice(idRoom, type); return rooms.getIdsDevice(idRoom, type);
} }

View file

@ -5,35 +5,35 @@ import java.util.ArrayList;
public class Room { public class Room {
static int compteur = 0; static int compteur = 0;
private int id; private final int id;
private String name; private final String name;
private ArrayList<Integer> temperatureSensors; private final ArrayList<Integer> temperatureSensors;
private ArrayList<Integer> lightSensors; private final ArrayList<Integer> lightSensors;
private ArrayList<Integer> co2Sensors; private final ArrayList<Integer> co2Sensors;
private ArrayList<Integer> gazSensors; private final ArrayList<Integer> gazSensors;
private ArrayList<Integer> studentCounters; private final ArrayList<Integer> studentCounters;
private ArrayList<Integer> doorActuator; private final ArrayList<Integer> doorActuator;
private ArrayList<Integer> windowActuator; private final ArrayList<Integer> windowActuator;
private ArrayList<Integer> alarmActuator; private final ArrayList<Integer> alarmActuator;
private ArrayList<Integer> heatingActuator; private final ArrayList<Integer> heatingActuator;
private ArrayList<Integer> climActuator; private final ArrayList<Integer> climActuator;
private ArrayList<Integer> lightActuator; private final ArrayList<Integer> lightActuator;
public Room(String name) { public Room(String name) {
this.id = Room.compteur; this.id = Room.compteur;
Room.compteur++; Room.compteur++;
this.name = name; this.name = name;
temperatureSensors = new ArrayList<Integer>(); temperatureSensors = new ArrayList<>();
lightSensors = new ArrayList<Integer>(); lightSensors = new ArrayList<>();
co2Sensors = new ArrayList<Integer>(); co2Sensors = new ArrayList<>();
gazSensors = new ArrayList<Integer>(); gazSensors = new ArrayList<>();
studentCounters = new ArrayList<Integer>(); studentCounters = new ArrayList<>();
doorActuator = new ArrayList<Integer>(); doorActuator = new ArrayList<>();
windowActuator = new ArrayList<Integer>(); windowActuator = new ArrayList<>();
alarmActuator = new ArrayList<Integer>(); alarmActuator = new ArrayList<>();
heatingActuator = new ArrayList<Integer>(); heatingActuator = new ArrayList<>();
climActuator = new ArrayList<Integer>(); climActuator = new ArrayList<>();
lightActuator = new ArrayList<Integer>(); lightActuator = new ArrayList<>();
} }
public int getId() { public int getId() {