import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class HelloController {
@Autowired
private SensorEndpointRepository m_repository;
@RequestMapping("/")
public String index() {
return "Greetings from Spring Boot!";
}
@RequestMapping(value = "/endpoints", method = RequestMethod.GET)
public List<SensorEndpoint> getAllEndpoints() {
Iterable<SensorEndpoint> all = m_repository.findAll();
return Lists.newArrayList(all);
}
@RequestMapping(value = "/endpoints/{id}", method = RequestMethod.GET)
public SensorEndpoint getEndpoint(@PathVariable("id") long id) {
return m_repository.findOne(id);
}
@RequestMapping(value = "/endpoints/add", method = RequestMethod.POST)
public SensorEndpoint addEndpoint(@RequestParam("name") String name,
@RequestParam("url") String endpointUrl) {
return m_repository.save(new SensorEndpoint(name, endpointUrl));
}
}