WIP
authorKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 12:16:41 +0000 (14:16 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 12:16:41 +0000 (14:16 +0200)
pom.xml
src/main/java/de/trion/kafka/outbox/OutboxController.java [deleted file]
src/main/java/de/trion/kafka/outbox/UserController.java [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index a69fe6c..87706cd 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jdbc</artifactId>
diff --git a/src/main/java/de/trion/kafka/outbox/OutboxController.java b/src/main/java/de/trion/kafka/outbox/OutboxController.java
deleted file mode 100644 (file)
index 86ff44f..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-package de.trion.kafka.outbox;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.ResponseEntity;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
-import org.springframework.web.util.UriComponents;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import java.time.LocalDateTime;
-
-@RestController
-@Transactional
-@RequestMapping("/users")
-public class OutboxController {
-
-    private static final Logger LOG = LoggerFactory.getLogger(OutboxController.class);
-
-
-    private final UserRepository repository;
-
-
-    public OutboxController(UserRepository repository) {
-        this.repository = repository;
-    }
-
-
-    @PostMapping
-    public ResponseEntity<Void> getVorgang(
-            ServletUriComponentsBuilder builder,
-            @RequestBody String username) {
-        String sanitizedUsername = OutboxController.sanitize(username);
-        User user = new User(sanitizedUsername, LocalDateTime.now(), false);
-        repository.save(user);
-        // TODO: Not-Unique Fehler auslösen
-        UriComponents uri =
-            builder
-                .fromCurrentRequest()
-                .path("{username}")
-                .buildAndExpand(sanitizedUsername);
-        return ResponseEntity.created(uri.toUri()).build();
-    }
-
-    @GetMapping("{username}")
-    public ResponseEntity<User> getUser(@PathVariable String username) {
-        User user = repository.findByUsername(OutboxController.sanitize(username));
-
-        if (user == null)
-            return ResponseEntity.notFound().build();
-
-        return ResponseEntity.ok(user);
-    }
-
-    private static String sanitize(String string) {
-        if (string == null)
-            return "";
-
-        return string.trim().toLowerCase();
-    }
-}
diff --git a/src/main/java/de/trion/kafka/outbox/UserController.java b/src/main/java/de/trion/kafka/outbox/UserController.java
new file mode 100644 (file)
index 0000000..163e254
--- /dev/null
@@ -0,0 +1,67 @@
+package de.trion.kafka.outbox;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.ResponseEntity;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
+import org.springframework.web.util.UriComponents;
+
+import java.time.LocalDateTime;
+
+@RestController
+@Transactional
+@RequestMapping("/users")
+public class UserController {
+
+    private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
+
+
+    private final UserRepository repository;
+
+
+    public UserController(UserRepository repository) {
+        this.repository = repository;
+    }
+
+
+    @PostMapping
+    public ResponseEntity<Void> getVorgang(
+            ServletUriComponentsBuilder builder,
+            @RequestBody String username) {
+        String sanitizedUsername = UserController.sanitize(username);
+        User user = new User(sanitizedUsername, LocalDateTime.now(), false);
+        repository.save(user);
+        // TODO: Not-Unique Fehler auslösen
+        UriComponents uri =
+            builder
+                .fromCurrentRequest()
+                .path("{username}")
+                .buildAndExpand(sanitizedUsername);
+        return ResponseEntity.created(uri.toUri()).build();
+    }
+
+    @GetMapping("{username}")
+    public ResponseEntity<User> getUser(@PathVariable String username) {
+        User user = repository.findByUsername(UserController.sanitize(username));
+
+        if (user == null)
+            return ResponseEntity.notFound().build();
+
+        return ResponseEntity.ok(user);
+    }
+
+    @GetMapping()
+    public ResponseEntity<Iterable<User>> getUsers() {
+        return ResponseEntity.ok(repository.findAll());
+    }
+
+
+    private static String sanitize(String string) {
+        if (string == null)
+            return "";
+
+        return string.trim().toLowerCase();
+    }
+}