From b1a4c8bc0d3aff1e8e06ed9036144c5254096a33 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 14 Mar 2021 10:54:30 +0100 Subject: [PATCH] WIP --- .../out/RemoteUsersServiceConsumer.java | 17 +++++++++-------- .../api/domain/PasswordRequestResult.java | 7 +++++++ .../api/domain/PasswordResetRequest.java | 13 +++++++++++++ .../pwreset/api/domain/PasswordRestService.java | 10 ++++++++++ .../demos/pwreset/api/out/MessagingService.java | 9 +++++++++ .../demos/pwreset/api/out/UsersService.java | 11 +++++++++++ .../de/juplo/demos/pwreset/domain/api/User.java | 15 --------------- .../demos/pwreset/domain/api/UsersService.java | 9 --------- .../out/RemoteUsersServiceConsumerIT.java | 9 +++------ 9 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRequestResult.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequest.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/api/out/MessagingService.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/api/out/UsersService.java delete mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/User.java delete mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/UsersService.java diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java index eb1492f..6755255 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java @@ -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 getUserByEmail(String email) { + public Optional getUserByEmail(String email) { ResponseEntity 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 index 0000000..5085f09 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRequestResult.java @@ -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 index 0000000..165c860 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordResetRequest.java @@ -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 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 index 0000000..d1d9d7a --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/domain/PasswordRestService.java @@ -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 index 0000000..460af93 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/MessagingService.java @@ -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 index 0000000..212b816 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/api/out/UsersService.java @@ -0,0 +1,11 @@ +package de.juplo.demos.pwreset.api.out; + +import java.util.Optional; +import java.util.UUID; + + +public interface UsersService +{ + Optional 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 index 9b7f913..0000000 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/User.java +++ /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 index 0580bd5..0000000 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/api/UsersService.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.juplo.demos.pwreset.domain.api; - -import java.util.Optional; - - -public interface UsersService -{ - Optional getUserByEmail(String email); -} diff --git a/pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java b/pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java index 3724a65..e84280c 100644 --- a/pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java +++ b/pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java @@ -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 result = usersService.getUserByEmail("pact@juplo.de"); + Optional 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); -- 2.20.1