From 7df01dd4a110b02cf438b8e24d0e8f7b9c025d00 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 14 Mar 2021 14:38:33 +0100 Subject: [PATCH] WIP --- .../pwreset/adapters/in/WebController.java | 16 +++---- ...Consumer.java => UsersServiceGateway.java} | 4 +- .../internal/PasswordResetProgress.java | 18 ++++++++ .../domain/internal/PasswordResetService.java | 33 ++++++++++++++ .../domain/ports/in/PasswordResetPort.java | 35 +++++++++++++++ .../in/PasswordResetRequestProgressDTO.java | 44 +++++++++++++++++++ .../domain/ports/in/PasswordResetService.java | 11 ----- .../domain/ports/in/ResetRequestProgress.java | 23 ---------- ...ssagingService.java => MessagingPort.java} | 2 +- .../out/{UsersService.java => UsersPort.java} | 2 +- ...a => UsersServiceGatewayContractTest.java} | 6 +-- 11 files changed, 145 insertions(+), 49 deletions(-) rename pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/{RemoteUsersServiceConsumer.java => UsersServiceGateway.java} (88%) create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetProgress.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetService.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetPort.java create mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetRequestProgressDTO.java delete mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetService.java delete mode 100644 pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/ResetRequestProgress.java rename pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/{MessagingService.java => MessagingPort.java} (78%) rename pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/{UsersService.java => UsersPort.java} (87%) rename pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/{RemoteUsersServiceConsumerIT.java => UsersServiceGatewayContractTest.java} (94%) diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java index 2d6b089..00f2510 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/adapters/in/WebController.java @@ -1,7 +1,7 @@ package de.juplo.demos.pwreset.adapters.in; -import de.juplo.demos.pwreset.domain.ports.in.ResetRequestProgress; -import de.juplo.demos.pwreset.domain.ports.in.PasswordResetService; +import de.juplo.demos.pwreset.domain.ports.in.PasswordResetRequestProgressDTO; +import de.juplo.demos.pwreset.domain.ports.in.PasswordResetPort; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; @@ -16,7 +16,7 @@ import java.util.UUID; @RequiredArgsConstructor public class WebController { - private final PasswordResetService passwordResetService; + private final PasswordResetPort passwordResetPort; @GetMapping("/") @@ -32,14 +32,14 @@ public class WebController throws IOException { - ResetRequestProgress progress = passwordResetService.request(email); + PasswordResetRequestProgressDTO progress = passwordResetPort.createRequest(email); httpServletResponse.sendRedirect(progress.getRequestId().toString()); } @GetMapping("/{id}") public ModelAndView getResetRequest(@PathVariable UUID id) { - ResetRequestProgress progress = passwordResetService.get(id); + PasswordResetRequestProgressDTO progress = passwordResetPort.getRequest(id); return createModelAndView(progress); } @@ -49,8 +49,8 @@ public class WebController @RequestParam String code, @RequestParam String password) { - ResetRequestProgress progress = - passwordResetService.confirm( + PasswordResetRequestProgressDTO progress = + passwordResetPort.confirmRequest( id, code, password); @@ -63,7 +63,7 @@ public class WebController return mav; } - ModelAndView createModelAndView(ResetRequestProgress progress) + ModelAndView createModelAndView(PasswordResetRequestProgressDTO progress) { ModelAndView mav = new ModelAndView(); mav.addObject("progress", progress); 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/UsersServiceGateway.java similarity index 88% rename from pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumer.java rename to pwreset/src/main/java/de/juplo/demos/pwreset/adapters/out/UsersServiceGateway.java index 7a2ac77..53b9d60 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/UsersServiceGateway.java @@ -1,6 +1,6 @@ package de.juplo.demos.pwreset.adapters.out; -import de.juplo.demos.pwreset.domain.ports.out.UsersService; +import de.juplo.demos.pwreset.domain.ports.out.UsersPort; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -11,7 +11,7 @@ import java.util.UUID; @RequiredArgsConstructor -public class RemoteUsersServiceConsumer implements UsersService +public class UsersServiceGateway implements UsersPort { private final String uriTemplate; private final RestTemplate restTemplate; diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetProgress.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetProgress.java new file mode 100644 index 0000000..757f692 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetProgress.java @@ -0,0 +1,18 @@ +package de.juplo.demos.pwreset.domain.internal; + +import lombok.Value; + + +@Value +public class PasswordResetProgress +{ + public enum Status + { + CONFIRMATION_DENIED, + CONFIMED, + ACCOMPLISHED + } + + private final Status status; + private final String message; +} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetService.java new file mode 100644 index 0000000..5d4b346 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/internal/PasswordResetService.java @@ -0,0 +1,33 @@ +package de.juplo.demos.pwreset.domain.internal; + +import java.util.Optional; +import java.util.UUID; + + +public class PasswordResetService +{ + public PasswordResetRequest createRequest(String email) + { + return null; + } + + public Optional findRequest(String email) + { + return null; + } + + public PasswordResetRequest getRequest(UUID requestId) + { + return null; + } + + public PasswordResetProgress confirmRequest(PasswordResetRequest request, String code, String password) + { + return null; + } + + public Optional getProgress(UUID requestId) + { + return null; + } +} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetPort.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetPort.java new file mode 100644 index 0000000..7f8a3f0 --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetPort.java @@ -0,0 +1,35 @@ +package de.juplo.demos.pwreset.domain.ports.in; + +import de.juplo.demos.pwreset.domain.internal.PasswordResetRequest; +import de.juplo.demos.pwreset.domain.internal.PasswordResetService; +import lombok.RequiredArgsConstructor; + +import java.util.Optional; +import java.util.UUID; + + +@RequiredArgsConstructor +public class PasswordResetPort +{ + private final PasswordResetService resetService; + + + public PasswordResetRequestProgressDTO createRequest(String email) + { + Optional result = + resetService.findRequest(email); + PasswordResetRequest request = + result.orElseGet(() -> resetService.createRequest(email)); + return PasswordResetRequestProgressDTO.from(request); + } + + public PasswordResetRequestProgressDTO getRequest(UUID requestId) + { + return PasswordResetRequestProgressDTO.from(resetService.getRequest(requestId)); + } + + public PasswordResetRequestProgressDTO confirmRequest(UUID requestId, String code, String password) + { + return PasswordResetRequestProgressDTO.from(resetService.confirmRequest(requestId, code, password)); + } +} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetRequestProgressDTO.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetRequestProgressDTO.java new file mode 100644 index 0000000..beb91fd --- /dev/null +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetRequestProgressDTO.java @@ -0,0 +1,44 @@ +package de.juplo.demos.pwreset.domain.ports.in; + +import de.juplo.demos.pwreset.domain.internal.PasswordResetProgress; +import de.juplo.demos.pwreset.domain.internal.PasswordResetRequest; +import de.juplo.demos.pwreset.domain.internal.PasswordResetRequestProgress; +import lombok.RequiredArgsConstructor; +import lombok.Value; + +import java.time.ZonedDateTime; +import java.util.Optional; +import java.util.UUID; + +import static de.juplo.demos.pwreset.domain.internal.PasswordResetProgress.Status.*; + + +@RequiredArgsConstructor +@Value +public class PasswordResetRequestProgressDTO +{ + private final UUID requestId; + private final boolean accepted; + private final String message; + private final Optional created; + private final Optional confirmed; + private final Optional accomplished; + + public static PasswordResetRequestProgressDTO from( + PasswordResetRequest request, + PasswordResetProgress progress) + { + return + new PasswordResetRequestProgressDTO( + request.getId(), + progress.getStatus() != CONFIRMATION_DENIED, + progress.getMessage(), + Optional.of(request.getCreated()), + progress.getStatus() == CONFIRMATION_DENIED + ? Optional.empty() + : Optional.of(request.getConfirmed()), + progress.getStatus() == ACCOMPLISHED + ? Optional.empty() + : Optional.of(request.getAccomplihed())); + } +} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetService.java deleted file mode 100644 index 833edd8..0000000 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/PasswordResetService.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.juplo.demos.pwreset.domain.ports.in; - -import java.util.UUID; - - -public interface PasswordResetService -{ - ResetRequestProgress request(String email); - ResetRequestProgress get(UUID requestId); - ResetRequestProgress confirm(UUID requestId, String code, String password); -} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/ResetRequestProgress.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/ResetRequestProgress.java deleted file mode 100644 index 5e70f5e..0000000 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/in/ResetRequestProgress.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.juplo.demos.pwreset.domain.ports.in; - -import lombok.Builder; -import lombok.Getter; -import lombok.ToString; - -import java.time.ZonedDateTime; -import java.util.Optional; -import java.util.UUID; - - -@Builder -@Getter -@ToString -public class ResetRequestProgress -{ - private final UUID requestId; - private final boolean accepted; - private final String message; - private final Optional created; - private final Optional confirmed; - private final Optional accomplished; -} diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingPort.java similarity index 78% rename from pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingService.java rename to pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingPort.java index b05411f..f904775 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingService.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/MessagingPort.java @@ -3,7 +3,7 @@ package de.juplo.demos.pwreset.domain.ports.out; import java.util.UUID; -public interface MessagingService +public interface MessagingPort { void sendRestCode(UUID userId, String code); } diff --git a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersService.java b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersPort.java similarity index 87% rename from pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersService.java rename to pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersPort.java index b314c86..bca7d82 100644 --- a/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersService.java +++ b/pwreset/src/main/java/de/juplo/demos/pwreset/domain/ports/out/UsersPort.java @@ -4,7 +4,7 @@ import java.util.Optional; import java.util.UUID; -public interface UsersService +public interface UsersPort { Optional getUserByEmail(String email); void setPassword(UUID userId, String password); 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/UsersServiceGatewayContractTest.java similarity index 94% rename from pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/RemoteUsersServiceConsumerIT.java rename to pwreset/src/test/java/de/juplo/demos/pwreset/adapters/out/UsersServiceGatewayContractTest.java index 2f58b21..4ab4c85 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/UsersServiceGatewayContractTest.java @@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.fail; @ExtendWith(PactConsumerTestExt.class) @PactTestFor(providerName = "UsersProvider") -public class RemoteUsersServiceConsumerIT +public class UsersServiceGatewayContractTest { @Pact(consumer="EmailServicesConsumer") public RequestResponsePact getExistingUserByEmail(PactDslWithProvider builder) @@ -47,8 +47,8 @@ public class RemoteUsersServiceConsumerIT new RestTemplateBuilder() .rootUri(mockServer.getUrl()) .build(); - RemoteUsersServiceConsumer usersService = - new RemoteUsersServiceConsumer( + UsersServiceGateway usersService = + new UsersServiceGateway( "/get?email={email}", restTemplate); try -- 2.20.1