aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/terminaldweller/doc/DocController.java8
-rw-r--r--src/main/java/com/terminaldweller/doc/DocService.java5
-rwxr-xr-xtests.sh6
3 files changed, 12 insertions, 7 deletions
diff --git a/src/main/java/com/terminaldweller/doc/DocController.java b/src/main/java/com/terminaldweller/doc/DocController.java
index e73ef41..39ddfe9 100644
--- a/src/main/java/com/terminaldweller/doc/DocController.java
+++ b/src/main/java/com/terminaldweller/doc/DocController.java
@@ -1,6 +1,6 @@
package com.terminaldweller.doc;
-import java.util.List;
+import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -24,9 +24,9 @@ public class DocController {
this.docService = docService;
}
- @GetMapping
- public List<Doc> getDocs() {
- return docService.getDocs();
+ @GetMapping(path = "{Id}")
+ public Optional<Doc> getDocs(@PathVariable("Id") Long id) {
+ return docService.getDocs(id);
}
@PostMapping
diff --git a/src/main/java/com/terminaldweller/doc/DocService.java b/src/main/java/com/terminaldweller/doc/DocService.java
index 5a07c23..c8bab23 100644
--- a/src/main/java/com/terminaldweller/doc/DocService.java
+++ b/src/main/java/com/terminaldweller/doc/DocService.java
@@ -1,6 +1,5 @@
package com.terminaldweller.doc;
-import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -15,8 +14,8 @@ public class DocService {
this.docRepository = docRepository;
}
- public List<Doc> getDocs() {
- return docRepository.findAll();
+ public Optional<Doc> getDocs(Long id) {
+ return docRepository.findById(id);
}
/**
diff --git a/tests.sh b/tests.sh
new file mode 100755
index 0000000..1187978
--- /dev/null
+++ b/tests.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+curl -X POST -H "Content-Type:application/json" -d '{"name":"doc1", "lastModified": 1652882691, "body":"Hello"}' "http://localhost:9080/api/v1/doc"
+curl -X GET "http://localhost:9080/api/v1/doc/2"
+curl -X DELETE "http://localhost:9080/api/v1/doc/1"
+curl -X PUT -H "Content-Type:application/json" -d '{"id": 1, "body": "Die before I do"}' "http://localhost:9080/api/v1/doc/1"