WIP
authorKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 11:55:38 +0000 (13:55 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 12 Jul 2020 11:55:38 +0000 (13:55 +0200)
src/main/java/de/trion/kafka/outbox/OutboxController.java
src/main/java/de/trion/kafka/outbox/UserRepository.java

index e1f8919..86ff44f 100644 (file)
@@ -31,15 +31,32 @@ public class OutboxController {
     public ResponseEntity<Void> getVorgang(
             ServletUriComponentsBuilder builder,
             @RequestBody String username) {
-        String cleaned = username.trim().toLowerCase();
-        User user = new User(cleaned, LocalDateTime.now(), false);
+        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(cleaned);
+            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();
+    }
 }
index 6791180..3437051 100644 (file)
@@ -7,5 +7,5 @@ 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("email") String username);
+    User findByUsername(@Param("username") String username);
 }