WIP
authorKai Moritz <kai@juplo.de>
Sun, 14 Mar 2021 09:54:30 +0000 (10:54 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 14 Mar 2021 09:54:30 +0000 (10:54 +0100)
pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java
pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRequestResult.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequest.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/api/out/MessagingService.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/api/out/UsersService.java [new file with mode: 0644]
pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/User.java [deleted file]
pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/UsersService.java [deleted file]
pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java

index eb1492f..6755255 100644 (file)
@@ -1,13 +1,13 @@
 package de.juplo.demos.pwreset.adapters.out;
 
-import de.juplo.demos.pwreset.domain.api.User;
-import de.juplo.demos.pwreset.domain.api.UsersService;
+import de.juplo.demos.pwreset.api.out.UsersService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.Optional;
+import java.util.UUID;
 
 
 @RequiredArgsConstructor
@@ -18,7 +18,7 @@ public class RemoteUsersServiceConsumer implements UsersService
 
 
   @Override
-  public Optional<User> getUserByEmail(String email) {
+  public Optional<UUID> getUserByEmail(String email) {
     ResponseEntity<UserDTO> response =
         restTemplate.getForEntity(uriTemplate, UserDTO.class, email);
     HttpStatus status = response.getStatusCode();
@@ -26,15 +26,16 @@ public class RemoteUsersServiceConsumer implements UsersService
     switch (response.getStatusCode()) {
       case OK:
         return
-            Optional.of(
-                User.builder()
-                    .id(dto.id)
-                    .email(dto.email)
-                    .build());
+            Optional.of(dto.id);
       case NOT_FOUND:
         return Optional.empty();
       default:
         throw new RuntimeException(status.toString());
     }
   }
+
+  @Override
+  public void setPassword(UUID userId, String password) {
+
+  }
 }
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRequestResult.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRequestResult.java
new file mode 100644 (file)
index 0000000..5085f09
--- /dev/null
@@ -0,0 +1,7 @@
+package de.juplo.demos.pwreset.api.domain;
+
+public enum PasswordRequestResult
+{
+  SUCCESSFUL,
+  WRONG_CODE
+}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequest.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequest.java
new file mode 100644 (file)
index 0000000..165c860
--- /dev/null
@@ -0,0 +1,13 @@
+package de.juplo.demos.pwreset.api.domain;
+
+import java.util.Optional;
+import java.util.UUID;
+
+
+public class PasswordResetRequest
+{
+  UUID id;
+  Optional<UUID> userId;
+  String code;
+  String password;
+}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java
new file mode 100644 (file)
index 0000000..d1d9d7a
--- /dev/null
@@ -0,0 +1,10 @@
+package de.juplo.demos.pwreset.api.domain;
+
+import java.util.UUID;
+
+
+public interface PasswordRestService
+{
+  PasswordResetRequest requestReset(UUID userId);
+  PasswordRequestResult performRequest(PasswordResetRequest request);
+}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/MessagingService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/MessagingService.java
new file mode 100644 (file)
index 0000000..460af93
--- /dev/null
@@ -0,0 +1,9 @@
+package de.juplo.demos.pwreset.api.out;
+
+import java.util.UUID;
+
+
+public interface MessagingService
+{
+  void sendRestCode(UUID userId, String code);
+}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/UsersService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/UsersService.java
new file mode 100644 (file)
index 0000000..212b816
--- /dev/null
@@ -0,0 +1,11 @@
+package de.juplo.demos.pwreset.api.out;
+
+import java.util.Optional;
+import java.util.UUID;
+
+
+public interface UsersService
+{
+  Optional<UUID> getUserByEmail(String email);
+  void setPassword(UUID userId, String password);
+}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/User.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/User.java
deleted file mode 100644 (file)
index 9b7f913..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-package de.juplo.demos.pwreset.domain.api;
-
-import lombok.Builder;
-import lombok.Data;
-
-import java.util.UUID;
-
-
-@Data
-@Builder
-public class User
-{
-  private UUID id;
-  private String email;
-}
diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/UsersService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/UsersService.java
deleted file mode 100644 (file)
index 0580bd5..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-package de.juplo.demos.pwreset.domain.api;
-
-import java.util.Optional;
-
-
-public interface UsersService
-{
-  Optional<User> getUserByEmail(String email);
-}
index 3724a65..e84280c 100644 (file)
@@ -6,7 +6,6 @@ import au.com.dius.pact.consumer.junit5.PactConsumerTestExt;
 import au.com.dius.pact.consumer.junit5.PactTestFor;
 import au.com.dius.pact.core.model.RequestResponsePact;
 import au.com.dius.pact.core.model.annotations.Pact;
-import de.juplo.demos.pwreset.domain.api.User;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.boot.web.client.RestTemplateBuilder;
@@ -35,7 +34,7 @@ public class RemoteUsersServiceConsumerIT
           .willRespondWith()
             .status(200)
             .headers(Map.of("Content-Type", "application/json;charset=UTF-8"))
-            .body("{\"id\": \"123e4567-e89b-12d3-a456-426614174000\", \"email\": \"pact@juplo.de\"}")
+            .body("{\"id\": \"123e4567-e89b-12d3-a456-426614174000\"}")
         .toPact();
   }
 
@@ -45,12 +44,10 @@ public class RemoteUsersServiceConsumerIT
     RestTemplate restTemplate = new RestTemplateBuilder().rootUri(mockServer.getUrl()).build();
     RemoteUsersServiceConsumer usersService = new RemoteUsersServiceConsumer("/get?email={email}", restTemplate);
     try {
-      Optional<User> result = usersService.getUserByEmail("pact@juplo.de");
+      Optional<UUID> result = usersService.getUserByEmail("pact@juplo.de");
 
       assertThat(result.isPresent()).isTrue();
-      User user = result.get();
-      assertThat(user.getId()).isEqualTo(UUID.fromString("123e4567-e89b-12d3-a456-426614174000"));
-      assertThat(user.getEmail()).isEqualTo("pact@juplo.de");
+      assertThat(result.get()).isEqualTo(UUID.fromString("123e4567-e89b-12d3-a456-426614174000"));
     }
     catch (Exception e) {
       fail("Unexpected exception", e);