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 56d4a95..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 68ab401..472c158 100755 --- a/git-hooks/pre-commit.sh +++ b/git-hooks/pre-commit.sh @@ -13,6 +13,8 @@ if [ "$NO_VERIFY" ]; then fi # list all added/copied/modified/renamed java files -git diff --staged --name-only --diff-filter=ACMR | egrep -a '.java$' | tr "\n" "\0" | - # run google-java-format on each file and re-stage any new changes - xargs -0 -I % echo "$format_cmd --aosp -i '%'; git add -f '%'" | sh +files="`git diff --staged --name-only --diff-filter=ACMR | egrep -a '.java$' | tr \"\\n\" \" \"`" +for f in $files; do + $format_cmd --aosp -i "$f" + git add -f "$f" +done diff --git a/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.java b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.java new file mode 100644 index 0000000..60f5c5d --- /dev/null +++ b/src/main/java/ch/usi/inf/sa4/sanmarinoes/smarthut/controller/DeviceController.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 DeviceController { + + @Autowired private DimmableLightRepository dimmableLightService; + + @GetMapping + public List getAll() { + return dimmableLightService.getList(); + } + + @GetMapping("/{id}") + public DimmableLight getById(@PathVariable("id") long id) { + return dimmableLightService.getList(); + } + + @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/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(),