50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
package de.ctdo.bunti.web;
|
|
|
|
import javax.validation.Valid;
|
|
import de.ctdo.bunti.control.BuntiController;
|
|
import de.ctdo.bunti.webmodel.DeviceUpdate;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.validation.Validator;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
@Controller
|
|
public class RestController {
|
|
private Validator validator;
|
|
private BuntiController controller;
|
|
|
|
@Autowired
|
|
public void setValidator(Validator validator) {
|
|
this.validator = validator;
|
|
}
|
|
|
|
@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", controller.getAllDevices());
|
|
}
|
|
|
|
@RequestMapping(value = "/devices/{id}", method = RequestMethod.GET)
|
|
public final ModelAndView getDeviceById(@PathVariable("id") int id) {
|
|
return new ModelAndView("device", "device", controller.getDeviceById(id));
|
|
}
|
|
|
|
// @RequestMapping(value = "/devices/{id}", method = RequestMethod.PUT)
|
|
// public String setDeviceById(@ModelAttribute @Valid DeviceUpdate update, BindingResult errors) {
|
|
// if (errors.hasErrors()) {
|
|
// return "redirect:/index.html";
|
|
// } else {
|
|
// controller.setDevice(update.getDeviceId(), update.getOptions());
|
|
// return "redirect:devices/" + update.getDeviceId();
|
|
// }
|
|
// }
|
|
|
|
}
|