feat: Room count people

This commit is contained in:
Jean-Remy Hok 2022-01-11 16:32:40 +01:00
parent 0acfba2520
commit fb1ab7247d
3 changed files with 40 additions and 2 deletions

View file

@ -52,4 +52,19 @@ public class RoomsServiceController {
return rooms.getIdsDevice(idRoom, type);
}
@GetMapping("/{id}/persons")
public Integer getPersons(@PathVariable("id") int id) {
return rooms.getPersons(id);
}
@PostMapping("/{id}/persons")
public Integer addPersons(@PathVariable("id") int idRoom, @RequestBody Integer nbPersons) {
return rooms.addPersons(idRoom, nbPersons);
}
@DeleteMapping("/{id}/persons")
public Integer removePersons(@PathVariable("id") int idRoom, @RequestBody Integer nbPersons) {
return rooms.removePersons(idRoom, nbPersons);
}
}

View file

@ -49,4 +49,28 @@ public class INSA {
public ArrayList<Integer> getIdsDevice(int idRoom, String type) {
return rooms.get(idRoom).getIdsDevice(type);
}
public Integer getPersons(int idRoom) {
Room room = rooms.get(idRoom);
if (room == null) return null;
else return room.countPeople;
}
public Integer addPersons(int idRoom, int nbPersons) {
Room room = rooms.get(idRoom);
if (room == null) return null;
else {
room.countPeople += nbPersons;
return room.countPeople;
}
}
public Integer removePersons(int idRoom, int nbPersons) {
Room room = rooms.get(idRoom);
if (room == null) return null;
else {
room.countPeople = Math.max(room.countPeople-nbPersons, 0); // Prevent having -1 person in a room
return room.countPeople;
}
}
}

View file

@ -18,6 +18,7 @@ public class Room {
private final ArrayList<Integer> heatingActuator;
private final ArrayList<Integer> climActuator;
private final ArrayList<Integer> lightActuator;
public Integer countPeople = 0;
public Room(String name) {
this.id = Room.compteur;
@ -139,11 +140,9 @@ public class Room {
return climActuator;
case "LIGHT_A":
return lightActuator;
default:
return null;
}
}
}