From d5084b1290c1db01c929b875767631cb9a5bac56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Ple=C3=9F?= Date: Wed, 7 Mar 2012 00:41:56 +0100 Subject: [PATCH] adding new REST controller --- .../de/ctdo/bunti/dao/BuntiDevicesDAO.java | 4 +- .../de/ctdo/bunti/web/RestController.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/ctdo/bunti/web/RestController.java diff --git a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java index 78fa900..13bd25c 100644 --- a/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java +++ b/src/main/java/de/ctdo/bunti/dao/BuntiDevicesDAO.java @@ -6,7 +6,9 @@ import de.ctdo.bunti.model.*; public interface BuntiDevicesDAO { + Collection getAllDevices(); Collection getAllDMXDevices(); BuntiDevice getDeviceById(int deviceId); - + + } diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java new file mode 100644 index 0000000..37f2907 --- /dev/null +++ b/src/main/java/de/ctdo/bunti/web/RestController.java @@ -0,0 +1,44 @@ +package de.ctdo.bunti.web; + +import de.ctdo.bunti.control.BuntiController; +import de.ctdo.bunti.dao.BuntiDevicesDAO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class RestController { + + private BuntiDevicesDAO devicesDAO; + private BuntiController controller; + + @Autowired + public final void setDevicesDAO(BuntiDevicesDAO devicesDAO) { + this.devicesDAO = devicesDAO; + } + + @Autowired + public final void setController(BuntiController controller) { + this.controller = controller; + } + + @RequestMapping(value = "/devices", method = RequestMethod.GET) + public final ModelAndView getAll() { + return new ModelAndView("deviceList", "deviceList", devicesDAO.getAllDevices()); + } + + @RequestMapping(value = "/devices/{id}", method = RequestMethod.GET) + public final ModelAndView getDeviceById(@PathVariable("id") int id) { + return new ModelAndView("device", "device", devicesDAO.getDeviceById(id)); + } + + @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT) + public final ModelAndView setDeviceById(@PathVariable("id") int id) { + //controller.setDevice(id, ... ) + return new ModelAndView("device", "device", devicesDAO.getDeviceById(id)); + } + +}