feat: Room count people

這個提交存在於:
Jean-Remy Hok 2022-01-11 16:32:40 +01:00
父節點 0acfba2520
當前提交 fb1ab7247d
共有 3 個檔案被更改,包括 40 行新增2 行删除

查看文件

@ -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);
}
}

查看文件

@ -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;
}
}
}

查看文件

@ -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;
}
}
}