WIP
authorKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 12:43:33 +0000 (14:43 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 12:43:33 +0000 (14:43 +0200)
12 files changed:
src/main/java/de/juplo/boot/data/jdbc/Application.java [new file with mode: 0644]
src/main/java/de/juplo/boot/data/jdbc/User.java [new file with mode: 0644]
src/main/java/de/juplo/boot/data/jdbc/UserController.java [new file with mode: 0644]
src/main/java/de/juplo/boot/data/jdbc/UserEvent.java [new file with mode: 0644]
src/main/java/de/juplo/boot/data/jdbc/UserRepository.java [new file with mode: 0644]
src/main/java/de/trion/kafka/outbox/Application.java [deleted file]
src/main/java/de/trion/kafka/outbox/User.java [deleted file]
src/main/java/de/trion/kafka/outbox/UserController.java [deleted file]
src/main/java/de/trion/kafka/outbox/UserEvent.java [deleted file]
src/main/java/de/trion/kafka/outbox/UserRepository.java [deleted file]
src/test/java/de/juplo/boot/data/jdbc/ApplicationTests.java [new file with mode: 0644]
src/test/java/de/trion/kafka/outbox/ApplicationTests.java [deleted file]

diff --git a/src/main/java/de/juplo/boot/data/jdbc/Application.java b/src/main/java/de/juplo/boot/data/jdbc/Application.java
new file mode 100644 (file)
index 0000000..d7301e1
--- /dev/null
@@ -0,0 +1,17 @@
+package de.juplo.boot.data.jdbc;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class Application {
+
+    private final static Logger LOG = LoggerFactory.getLogger(Application.class);
+
+
+    public static void main(String[] args) {
+        SpringApplication.run(Application.class, args);
+    }
+}
diff --git a/src/main/java/de/juplo/boot/data/jdbc/User.java b/src/main/java/de/juplo/boot/data/jdbc/User.java
new file mode 100644 (file)
index 0000000..6d4d552
--- /dev/null
@@ -0,0 +1,26 @@
+package de.juplo.boot.data.jdbc;
+
+import lombok.*;
+import org.springframework.data.annotation.Id;
+
+import java.time.LocalDateTime;
+
+public class User {
+    @Id
+    Long id;
+    @Getter
+    @Setter
+    String username;
+    @Getter
+    @Setter
+    LocalDateTime created;
+    @Getter
+    @Setter
+    boolean loggedIn;
+
+    public User(String username, LocalDateTime created, boolean loggedIn) {
+        this.username = username;
+        this.created = created;
+        this.loggedIn = loggedIn;
+    }
+}
diff --git a/src/main/java/de/juplo/boot/data/jdbc/UserController.java b/src/main/java/de/juplo/boot/data/jdbc/UserController.java
new file mode 100644 (file)
index 0000000..1ff11d8
--- /dev/null
@@ -0,0 +1,67 @@
+package de.juplo.boot.data.jdbc;
+
+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();
+    }
+}
diff --git a/src/main/java/de/juplo/boot/data/jdbc/UserEvent.java b/src/main/java/de/juplo/boot/data/jdbc/UserEvent.java
new file mode 100644 (file)
index 0000000..fd132c3
--- /dev/null
@@ -0,0 +1,9 @@
+package de.juplo.boot.data.jdbc;
+
+public class UserEvent {
+    public enum Type { CREATED, LOGIN, LOGOUT, DELETED }
+
+    Long id;
+    Type type;
+    String user;
+}
diff --git a/src/main/java/de/juplo/boot/data/jdbc/UserRepository.java b/src/main/java/de/juplo/boot/data/jdbc/UserRepository.java
new file mode 100644 (file)
index 0000000..1d07359
--- /dev/null
@@ -0,0 +1,10 @@
+package de.juplo.boot.data.jdbc;
+
+import org.springframework.data.jdbc.repository.query.Query;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.Param;
+
+public interface UserRepository extends CrudRepository<User, Long> {
+    @Query("select * from User u where u.username = :username")
+    User findByUsername(@Param("username") String username);
+}
diff --git a/src/main/java/de/trion/kafka/outbox/Application.java b/src/main/java/de/trion/kafka/outbox/Application.java
deleted file mode 100644 (file)
index f6865f5..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-package de.trion.kafka.outbox;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class Application {
-
-    private final static Logger LOG = LoggerFactory.getLogger(Application.class);
-
-
-    public static void main(String[] args) {
-        SpringApplication.run(Application.class, args);
-    }
-}
diff --git a/src/main/java/de/trion/kafka/outbox/User.java b/src/main/java/de/trion/kafka/outbox/User.java
deleted file mode 100644 (file)
index f4d1c8c..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-package de.trion.kafka.outbox;
-
-import lombok.*;
-import org.springframework.data.annotation.Id;
-
-import java.time.LocalDateTime;
-
-public class User {
-    @Id
-    Long id;
-    @Getter
-    @Setter
-    String username;
-    @Getter
-    @Setter
-    LocalDateTime created;
-    @Getter
-    @Setter
-    boolean loggedIn;
-
-    public User(String username, LocalDateTime created, boolean loggedIn) {
-        this.username = username;
-        this.created = created;
-        this.loggedIn = loggedIn;
-    }
-}
diff --git a/src/main/java/de/trion/kafka/outbox/UserController.java b/src/main/java/de/trion/kafka/outbox/UserController.java
deleted file mode 100644 (file)
index 163e254..0000000
+++ /dev/null
@@ -1,67 +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 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();
-    }
-}
diff --git a/src/main/java/de/trion/kafka/outbox/UserEvent.java b/src/main/java/de/trion/kafka/outbox/UserEvent.java
deleted file mode 100644 (file)
index d22106c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package de.trion.kafka.outbox;
-
-public class UserEvent {
-    public enum Type { CREATED, LOGIN, LOGOUT, DELETED }
-
-    Long id;
-    Type type;
-    String user;
-}
diff --git a/src/main/java/de/trion/kafka/outbox/UserRepository.java b/src/main/java/de/trion/kafka/outbox/UserRepository.java
deleted file mode 100644 (file)
index 3437051..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-package de.trion.kafka.outbox;
-
-import org.springframework.data.jdbc.repository.query.Query;
-import org.springframework.data.repository.CrudRepository;
-import org.springframework.data.repository.query.Param;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-public interface UserRepository extends CrudRepository<User, Long> {
-    @Query("select * from User u where u.username = :username")
-    User findByUsername(@Param("username") String username);
-}
diff --git a/src/test/java/de/juplo/boot/data/jdbc/ApplicationTests.java b/src/test/java/de/juplo/boot/data/jdbc/ApplicationTests.java
new file mode 100644 (file)
index 0000000..c77d5b7
--- /dev/null
@@ -0,0 +1,16 @@
+package de.juplo.boot.data.jdbc;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class ApplicationTests {
+
+    @Test
+    public void contextLoads() {
+    }
+
+}
diff --git a/src/test/java/de/trion/kafka/outbox/ApplicationTests.java b/src/test/java/de/trion/kafka/outbox/ApplicationTests.java
deleted file mode 100644 (file)
index 0962964..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-package de.trion.kafka.outbox;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest
-public class ApplicationTests {
-
-    @Test
-    public void contextLoads() {
-    }
-
-}