added controllers and fixed RoomRepository

This commit is contained in:
Tommaso Rodolfo Masera 2020-02-25 16:04:11 +01:00
parent 03fed60a34
commit a3128b7cb7
5 changed files with 161 additions and 1 deletions

View file

@ -0,0 +1,40 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
@RequestMapping("/room")
public class RoomController {
@Autowired private RoomRepository roomRepository;
@GetMapping
public Iterable<Room> findAll() {
return roomRepository.findAll();
}
@GetMapping("/{id}")
public Optional<Room> findById(@PathVariable("id") long id) {
return roomRepository.findById(id);
}
@PostMapping
public Room save(@RequestBody Room r) {
return roomRepository.save(r);
}
@PutMapping("/{id}")
public Room update(@RequestBody Room r) {
return roomRepository.save(r);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable("id") long id) {
roomRepository.deleteById(id);
}
}

View file

@ -0,0 +1,40 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
@RequestMapping("/sensor")
public class SensorController {
@Autowired private SensorRepository sensorRepository;
@GetMapping
public Iterable<Sensor> findAll() {
return sensorRepository.findAll();
}
@GetMapping("/{id}")
public Optional<Sensor> findById(@PathVariable("id") long id) {
return sensorRepository.findById(id);
}
@PostMapping
public Sensor save(@RequestBody Sensor s) {
return sensorRepository.save(s);
}
@PutMapping("/{id}")
public Sensor update(@RequestBody Sensor s) {
return sensorRepository.save(s);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable("id") long id) {
sensorRepository.deleteById(id);
}
}

View file

@ -0,0 +1,40 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
@RequestMapping("/smartplug")
public class SmartPlugController {
@Autowired private SmartPlugRepository smartPlugRepository;
@GetMapping
public Iterable<SmartPlug> findAll() {
return smartPlugRepository.findAll();
}
@GetMapping("/{id}")
public Optional<SmartPlug> findById(@PathVariable("id") long id) {
return smartPlugRepository.findById(id);
}
@PostMapping
public SmartPlug save(@RequestBody SmartPlug sp) {
return smartPlugRepository.save(sp);
}
@PutMapping("/{id}")
public SmartPlug update(@RequestBody SmartPlug sp) {
return smartPlugRepository.save(sp);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable("id") long id) {
smartPlugRepository.deleteById(id);
}
}

View file

@ -0,0 +1,40 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
@RequestMapping("/switch")
public class SwitchController {
@Autowired private SwitchRepository switchRepository;
@GetMapping
public Iterable<Switch> findAll() {
return switchRepository.findAll();
}
@GetMapping("/{id}")
public Optional<Switch> findById(@PathVariable("id") long id) {
return switchRepository.findById(id);
}
@PostMapping
public Switch save(@RequestBody Switch s) {
return switchRepository.save(s);
}
@PutMapping("/{id}")
public Switch update(@RequestBody Switch s) {
return switchRepository.save(s);
}
@DeleteMapping("/{id}")
public void deleteById(@PathVariable("id") long id) {
switchRepository.deleteById(id);
}
}

View file

@ -2,4 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
public interface RoomRepository extends CrudRepository<Room, User> {} public interface RoomRepository extends CrudRepository<Room, Long> {}