2012-03-20 23:44:55 +00:00
|
|
|
package de.ctdo.bunti.web;
|
|
|
|
|
2012-03-25 15:58:07 +00:00
|
|
|
import de.ctdo.bunti.dao.RoomsDAO;
|
|
|
|
import de.ctdo.bunti.model.BuntiDevice;
|
2012-03-20 23:44:55 +00:00
|
|
|
import de.ctdo.bunti.model.Room;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
2012-03-25 15:58:07 +00:00
|
|
|
import java.util.List;
|
2012-03-20 23:44:55 +00:00
|
|
|
|
|
|
|
@Controller
|
|
|
|
@RequestMapping(value = "/rooms")
|
|
|
|
public class RoomsController {
|
2012-03-25 15:58:07 +00:00
|
|
|
private RoomsDAO roomsDAO;
|
2012-03-20 23:44:55 +00:00
|
|
|
|
|
|
|
@Autowired
|
2012-03-25 15:58:07 +00:00
|
|
|
public void setRoomsDAO(RoomsDAO roomsDAO) {
|
|
|
|
this.roomsDAO = roomsDAO;
|
2012-03-20 23:44:55 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 00:04:53 +00:00
|
|
|
@RequestMapping(value = "", method = RequestMethod.GET)
|
2012-03-20 23:44:55 +00:00
|
|
|
public @ResponseBody Collection<Room> getAll() {
|
2012-03-25 15:58:07 +00:00
|
|
|
return roomsDAO.getRooms();
|
2012-03-20 23:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
2012-03-21 22:43:00 +00:00
|
|
|
public @ResponseBody Room getRoomById(@PathVariable("id") int id) {
|
2012-03-25 15:58:07 +00:00
|
|
|
return roomsDAO.getRoom(id);
|
2012-03-21 22:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/{id}/devices", method = RequestMethod.GET)
|
2012-03-25 15:58:07 +00:00
|
|
|
public @ResponseBody
|
|
|
|
List<BuntiDevice> getDevicesFromRoom(@PathVariable("id") int id) {
|
|
|
|
Room room = roomsDAO.getRoom(id);
|
2012-03-21 22:43:00 +00:00
|
|
|
|
2012-03-25 15:58:07 +00:00
|
|
|
if(room != null) {
|
|
|
|
return room.getDevices();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2012-03-20 23:44:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|