diff --git a/.gitignore b/.gitignore
index 80f92bb..69ca520 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
+**/.DS_Store
+
# Compiled class file
*.class
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 241f098..7c6191b 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
diff --git a/git-hooks/pre-commit.sh b/git-hooks/pre-commit.sh
index 760f9a7..472c158 100755
--- a/git-hooks/pre-commit.sh
+++ b/git-hooks/pre-commit.sh
@@ -13,9 +13,8 @@ if [ "$NO_VERIFY" ]; then
fi
# list all added/copied/modified/renamed java files
-files="$(git diff --staged --name-only --diff-filter=ACMR | egrep -a '.java$' | tr '\n' ' ')"
+files="`git diff --staged --name-only --diff-filter=ACMR | egrep -a '.java$' | tr \"\\n\" \" \"`"
for f in $files; do
- # run google-java-format on each file and re-stage any new changes
- $format_cmd --aosp -i "$f"
- git add -f "$f"
+ $format_cmd --aosp -i "$f"
+ git add -f "$f"
done
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java
new file mode 100644
index 0000000..1098824
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/ButtonDimmerController.java
@@ -0,0 +1,47 @@
+package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
+
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmer;
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.ButtonDimmerRepository;
+import java.util.Optional;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@EnableAutoConfiguration
+@RequestMapping("/buttonDimmer")
+public class ButtonDimmerController {
+ @Autowired private ButtonDimmerRepository buttonDimmerService;
+
+ @GetMapping
+ public Iterable findAll() {
+ return buttonDimmerService.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return buttonDimmerService.findById(id);
+ }
+
+ @PostMapping
+ public ButtonDimmer save(@RequestBody ButtonDimmer bd) {
+ return buttonDimmerService.save(bd);
+ }
+
+ @PutMapping
+ public ButtonDimmer update(@RequestBody ButtonDimmer bd) {
+ return buttonDimmerService.save(bd);
+ }
+
+ @DeleteMapping("/{id}")
+ public void delete(@PathVariable("id") long id) {
+ buttonDimmerService.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java
new file mode 100644
index 0000000..0cd1144
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DimmableLightController.java
@@ -0,0 +1,48 @@
+package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
+
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLight;
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.DimmableLightRepository;
+import java.util.List;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@EnableAutoConfiguration
+@RequestMapping("/dimmableLight")
+public class DimmableLightController {
+
+ @Autowired private DimmableLightRepository dimmableLightService;
+
+ @GetMapping
+ public List getAll() {
+ return dimmableLightService.getList();
+ }
+
+ @GetMapping("/{id}")
+ public DimmableLight getById(@PathVariable("id") long id) {
+ return dimmableLightService.getById();
+ }
+
+ @PostMapping
+ public DimmableLight create(@RequestBody DimmableLight dl) {
+ return dimmableLightService.create(dl);
+ }
+
+ @PutMapping("/{id}")
+ public DimmableLight update(@PathVariable("id") long id, @RequestBody DimmableLight dl) {
+ return dimmableLightService.update(id, dl);
+ }
+
+ @DeleteMapping("/{id}")
+ public void delete(@PathVariable("id") long id) {
+ dimmableLightService.delete(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java
new file mode 100644
index 0000000..0696202
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/KnobDimmerController.java
@@ -0,0 +1,48 @@
+package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
+
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmer;
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.KnobDimmerRepository;
+import java.util.Optional;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@EnableAutoConfiguration
+@RequestMapping("/knobDimmer")
+public class KnobDimmerController {
+
+ @Autowired private KnobDimmerRepository knobDimmerService;
+
+ @GetMapping
+ public Iterable findAll() {
+ return knobDimmerService.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return knobDimmerService.findById(id);
+ }
+
+ @PostMapping
+ public KnobDimmer save(@RequestBody KnobDimmer kd) {
+ return knobDimmerService.save(kd);
+ }
+
+ @PutMapping
+ public KnobDimmer update(@RequestBody KnobDimmer kd) {
+ return knobDimmerService.save(kd);
+ }
+
+ @DeleteMapping("/{id}")
+ public void delete(@PathVariable("id") long id) {
+ knobDimmerService.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java
new file mode 100644
index 0000000..5ac2612
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/MotionSensorController.java
@@ -0,0 +1,48 @@
+package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
+
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensor;
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.MotionSensorRepository;
+import java.util.Optional;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@EnableAutoConfiguration
+@RequestMapping("/motionSensor")
+public class MotionSensorController {
+
+ @Autowired private MotionSensorRepository motionSensorService;
+
+ @GetMapping
+ public Iterable findAll() {
+ return motionSensorService.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return motionSensorService.findById(id);
+ }
+
+ @PostMapping
+ public MotionSensor save(@RequestBody MotionSensor ms) {
+ return motionSensorService.save(ms);
+ }
+
+ @PutMapping
+ public MotionSensor update(@RequestBody MotionSensor ms) {
+ return motionSensorService.save(ms);
+ }
+
+ @DeleteMapping("/{id}")
+ public void delete(@PathVariable("id") long id) {
+ motionSensorService.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java
new file mode 100644
index 0000000..9a97abb
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RegularLightController.java
@@ -0,0 +1,48 @@
+package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
+
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RegularLight;
+import ch.usi.inf.sa4.sanmarinoes.smarthut.models.RegularLightRepository;
+import java.util.Optional;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@EnableAutoConfiguration
+@RequestMapping("/regularLight")
+public class RegularLightController {
+
+ @Autowired private RegularLightRepository regularLightService;
+
+ @GetMapping
+ public Iterable findAll() {
+ return regularLightService.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return regularLightService.findById(id);
+ }
+
+ @PostMapping
+ public RegularLight save(@RequestBody RegularLight rl) {
+ return regularLightService.save(rl);
+ }
+
+ @PutMapping
+ public RegularLight update(@RequestBody RegularLight rl) {
+ return regularLightService.save(rl);
+ }
+
+ @DeleteMapping("/{id}")
+ public void delete(@PathVariable("id") long id) {
+ regularLightService.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java
new file mode 100644
index 0000000..c60d45b
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/RoomController.java
@@ -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 findAll() {
+ return roomRepository.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return roomRepository.findById(id);
+ }
+
+ @PostMapping
+ public Room save(@RequestBody Room r) {
+ return roomRepository.save(r);
+ }
+
+ @PutMapping
+ public Room update(@RequestBody Room r) {
+ return roomRepository.save(r);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteById(@PathVariable("id") long id) {
+ roomRepository.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java
new file mode 100644
index 0000000..04fe6fb
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SensorController.java
@@ -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 findAll() {
+ return sensorRepository.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return sensorRepository.findById(id);
+ }
+
+ @PostMapping
+ public Sensor save(@RequestBody Sensor s) {
+ return sensorRepository.save(s);
+ }
+
+ @PutMapping
+ public Sensor update(@RequestBody Sensor s) {
+ return sensorRepository.save(s);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteById(@PathVariable("id") long id) {
+ sensorRepository.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java
new file mode 100644
index 0000000..a6304b4
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SmartPlugController.java
@@ -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 findAll() {
+ return smartPlugRepository.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return smartPlugRepository.findById(id);
+ }
+
+ @PostMapping
+ public SmartPlug save(@RequestBody SmartPlug sp) {
+ return smartPlugRepository.save(sp);
+ }
+
+ @PutMapping
+ public SmartPlug update(@RequestBody SmartPlug sp) {
+ return smartPlugRepository.save(sp);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteById(@PathVariable("id") long id) {
+ smartPlugRepository.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java
new file mode 100644
index 0000000..4cceb34
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/SwitchController.java
@@ -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 findAll() {
+ return switchRepository.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return switchRepository.findById(id);
+ }
+
+ @PostMapping
+ public Switch save(@RequestBody Switch s) {
+ return switchRepository.save(s);
+ }
+
+ @PutMapping
+ public Switch update(@RequestBody Switch s) {
+ return switchRepository.save(s);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteById(@PathVariable("id") long id) {
+ switchRepository.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java
new file mode 100644
index 0000000..941cf9b
--- /dev/null
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/UserController.java
@@ -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("/user")
+public class UserController {
+
+ @Autowired private UserRepository userRepository;
+
+ @GetMapping
+ public Iterable findAll() {
+ return userRepository.findAll();
+ }
+
+ @GetMapping("/{id}")
+ public Optional findById(@PathVariable("id") long id) {
+ return userRepository.findById(id);
+ }
+
+ @PostMapping
+ public User save(@RequestBody User u) {
+ return userRepository.save(u);
+ }
+
+ @PutMapping
+ public User update(@RequestBody User u) {
+ return userRepository.save(u);
+ }
+
+ @DeleteMapping("/{id}")
+ public void deleteById(@PathVariable("id") long id) {
+ userRepository.deleteById(id);
+ }
+}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java
index e462306..8cbb5d5 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/WelcomeController.java
@@ -3,15 +3,14 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.controller;
import ch.usi.inf.sa4.sanmarinoes.smarthut.models.*;
import java.util.*;
import org.springframework.boot.autoconfigure.*;
-import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@RestController
@EnableAutoConfiguration
-@Controller
+// @Mapping("/light")
public class WelcomeController {
- @GetMapping("/")
+ @GetMapping
List testDevices() {
return Arrays.asList(
new KnobDimmer(),
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java
index ec732b1..6f36557 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/Room.java
@@ -12,6 +12,18 @@ public class Room {
@Column(name = "id", updatable = false, nullable = false)
private Long id;
+ /**
+ * Icon and image are to be given as byte[]. In order to get an encoded string from it, the
+ * Base64.getEncoder().encodeToString(byte[] content) should be used. For further information:
+ * https://www.baeldung.com/java-base64-image-string
+ * https://docs.oracle.com/javase/8/docs/api/java/util/Base64.html
+ */
+ @Column(name = "icon", updatable = true, nullable = false)
+ private byte[] icon;
+
+ @Column(name = "image", updatable = true, nullable = false)
+ private byte[] image;
+
/** User that owns the house this room is in */
@ManyToOne
@JoinColumn(name = "user_id")
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java
index d9efb14..08b4298 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/RoomRepository.java
@@ -2,4 +2,4 @@ package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
import org.springframework.data.repository.CrudRepository;
-public interface RoomRepository extends CrudRepository {}
+public interface RoomRepository extends CrudRepository {}
diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java
index c2bf0c2..0b8c62a 100644
--- a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java
+++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/models/UserRepository.java
@@ -1,5 +1,6 @@
package ch.usi.inf.sa4.sanmarinoes.smarthut.models;
+import java.util.*;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository {