From 3c8b47c86249b52fcdb9275c40d161fb3e6bcc98 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 12 Jul 2020 14:16:41 +0200 Subject: [PATCH] WIP --- pom.xml | 4 ++++ ...utboxController.java => UserController.java} | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) rename src/main/java/de/trion/kafka/outbox/{OutboxController.java => UserController.java} (76%) diff --git a/pom.xml b/pom.xml index a69fe6c..87706cd 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-actuator + org.springframework.boot spring-boot-starter-data-jdbc diff --git a/src/main/java/de/trion/kafka/outbox/OutboxController.java b/src/main/java/de/trion/kafka/outbox/UserController.java similarity index 76% rename from src/main/java/de/trion/kafka/outbox/OutboxController.java rename to src/main/java/de/trion/kafka/outbox/UserController.java index 86ff44f..163e254 100644 --- a/src/main/java/de/trion/kafka/outbox/OutboxController.java +++ b/src/main/java/de/trion/kafka/outbox/UserController.java @@ -7,22 +7,21 @@ 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 { +public class UserController { - private static final Logger LOG = LoggerFactory.getLogger(OutboxController.class); + private static final Logger LOG = LoggerFactory.getLogger(UserController.class); private final UserRepository repository; - public OutboxController(UserRepository repository) { + public UserController(UserRepository repository) { this.repository = repository; } @@ -31,7 +30,7 @@ public class OutboxController { public ResponseEntity getVorgang( ServletUriComponentsBuilder builder, @RequestBody String username) { - String sanitizedUsername = OutboxController.sanitize(username); + String sanitizedUsername = UserController.sanitize(username); User user = new User(sanitizedUsername, LocalDateTime.now(), false); repository.save(user); // TODO: Not-Unique Fehler auslösen @@ -45,7 +44,7 @@ public class OutboxController { @GetMapping("{username}") public ResponseEntity getUser(@PathVariable String username) { - User user = repository.findByUsername(OutboxController.sanitize(username)); + User user = repository.findByUsername(UserController.sanitize(username)); if (user == null) return ResponseEntity.notFound().build(); @@ -53,6 +52,12 @@ public class OutboxController { return ResponseEntity.ok(user); } + @GetMapping() + public ResponseEntity> getUsers() { + return ResponseEntity.ok(repository.findAll()); + } + + private static String sanitize(String string) { if (string == null) return ""; -- 2.20.1