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
@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();
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) {
+
+ }
}
--- /dev/null
+package de.juplo.demos.pwreset.api.domain;
+
+public enum PasswordRequestResult
+{
+ SUCCESSFUL,
+ WRONG_CODE
+}
--- /dev/null
+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;
+}
--- /dev/null
+package de.juplo.demos.pwreset.api.domain;
+
+import java.util.UUID;
+
+
+public interface PasswordRestService
+{
+ PasswordResetRequest requestReset(UUID userId);
+ PasswordRequestResult performRequest(PasswordResetRequest request);
+}
--- /dev/null
+package de.juplo.demos.pwreset.api.out;
+
+import java.util.UUID;
+
+
+public interface MessagingService
+{
+ void sendRestCode(UUID userId, String code);
+}
--- /dev/null
+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);
+}
+++ /dev/null
-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;
-}
+++ /dev/null
-package de.juplo.demos.pwreset.domain.api;
-
-import java.util.Optional;
-
-
-public interface UsersService
-{
- Optional<User> getUserByEmail(String email);
-}
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;
.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();
}
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);