From 64f90ce10935e71ab12f5f98892fa78b771eb3ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 21 Mar 2012 00:44:41 +0100 Subject: [PATCH 1/3] rooms controller --- .../java/de/ctdo/bunti/control/BuntiController.java | 4 ++++ .../de/ctdo/bunti/control/BuntiControllerImpl.java | 10 ++++++++++ src/main/java/de/ctdo/bunti/web/RestController.java | 1 - 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/ctdo/bunti/control/BuntiController.java b/src/main/java/de/ctdo/bunti/control/BuntiController.java index ae9f0f1..0374d7c 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiController.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiController.java @@ -1,6 +1,7 @@ package de.ctdo.bunti.control; import de.ctdo.bunti.model.BuntiDevice; +import de.ctdo.bunti.model.Room; import java.util.Collection; import java.util.Map; @@ -12,4 +13,7 @@ public interface BuntiController { boolean updateDeviceData(int deviceId, Map options); + Collection getAllRooms(); + Room getRoomById(int roomId); + } diff --git a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java index bca6fbb..9f99185 100644 --- a/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java +++ b/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java @@ -54,6 +54,16 @@ public class BuntiControllerImpl implements BuntiController, ApplicationEventPub return false; } + @Override + public Collection getAllRooms() { + return roomsDAO.getRooms(); + } + + @Override + public Room getRoomById(int roomId) { + return roomsDAO.getRoom(roomId); + } + @Override public Collection getAllDevices() { return devicesDAO.getAllDevices(); diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java index a6ebce6..5e846a3 100644 --- a/src/main/java/de/ctdo/bunti/web/RestController.java +++ b/src/main/java/de/ctdo/bunti/web/RestController.java @@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.validation.Validator; import java.util.*; @Controller From 8b362e1ebc931dae1f91f906bb2ecde36e7b29f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 21 Mar 2012 00:44:55 +0100 Subject: [PATCH 2/3] rooms controller --- .../de/ctdo/bunti/web/RoomsController.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/main/java/de/ctdo/bunti/web/RoomsController.java diff --git a/src/main/java/de/ctdo/bunti/web/RoomsController.java b/src/main/java/de/ctdo/bunti/web/RoomsController.java new file mode 100644 index 0000000..5928cf1 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/web/RoomsController.java @@ -0,0 +1,38 @@ +package de.ctdo.bunti.web; + +import de.ctdo.bunti.control.BuntiController; +import de.ctdo.bunti.model.Room; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.Collection; + +@Controller +@RequestMapping(value = "/rooms") +public class RoomsController { + private static final Logger LOGGER = LoggerFactory.getLogger(RoomsController.class); + private BuntiController controller; + + + @Autowired + public final void setController(BuntiController controller) { + this.controller = controller; + } + + @RequestMapping(value = "/", method = RequestMethod.GET) + public @ResponseBody Collection getAll() { + LOGGER.info("handle GET /rooms/" + " request"); + return controller.getAllRooms(); + } + + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public @ResponseBody + Room getDeviceById(@PathVariable("id") int id) { + LOGGER.info("handle GET /rooms/id" + id + " request"); + return controller.getRoomById(id); + } + +} From 4f755abce6995cfbb4425e23e64170b8f1c18dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 21 Mar 2012 01:04:53 +0100 Subject: [PATCH 3/3] rooms controller --- src/main/java/de/ctdo/bunti/web/RoomsController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/ctdo/bunti/web/RoomsController.java b/src/main/java/de/ctdo/bunti/web/RoomsController.java index 5928cf1..bddcb1b 100644 --- a/src/main/java/de/ctdo/bunti/web/RoomsController.java +++ b/src/main/java/de/ctdo/bunti/web/RoomsController.java @@ -22,7 +22,7 @@ public class RoomsController { this.controller = controller; } - @RequestMapping(value = "/", method = RequestMethod.GET) + @RequestMapping(value = "", method = RequestMethod.GET) public @ResponseBody Collection getAll() { LOGGER.info("handle GET /rooms/" + " request"); return controller.getAllRooms();