bunti/src/main/java/de/ctdo/bunti/web/RestController.java

44 lines
1.4 KiB
Java

package de.ctdo.bunti.web;
import de.ctdo.bunti.control.BuntiController;
import de.ctdo.bunti.model.BuntiDevice;
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;
import java.util.Map;
@Controller
public class RestController {
private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class);
@Autowired
private BuntiController controller;
@RequestMapping(value = "/devices", method = RequestMethod.GET)
@ResponseBody
public Collection<BuntiDevice> getAll() {
LOGGER.info("handle GET /devices request");
return controller.getAllDevices();
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
@ResponseBody
public BuntiDevice getDeviceById(@PathVariable("id") int id) {
LOGGER.info("handle GET /devices/" + id + " request");
return controller.getDeviceById(id);
}
@RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT)
public String setDeviceById(@PathVariable("id") int id, @RequestBody Map<String, Object> update) {
LOGGER.info("handle PUT /devices/" + id + " request update=" + update.toString() );
controller.updateDeviceData(id, update);
return "redirect:devices/" + id;
}
}