From 5bffe60126c5fa74bff59c91dfbd722d291b1c93 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 11 Jun 2021 17:48:29 +0200 Subject: [PATCH] WIP --- .../transfer/TransferServiceApplication.java | 6 ++--- .../payment/transfer/api/TransferService.java | 6 ----- .../controller/TransferController.java | 12 +++++----- .../TransferRequest.java} | 4 ++-- .../payment/transfer/domain/Transfer.java | 23 +++++++++++++++++++ .../TransferRepository.java | 4 ++-- .../TransferService.java} | 12 ++-------- 7 files changed, 38 insertions(+), 29 deletions(-) delete mode 100644 transfer/src/main/java/de/juplo/kafka/payment/transfer/api/TransferService.java rename transfer/src/main/java/de/juplo/kafka/payment/transfer/{api/Transfer.java => controller/TransferRequest.java} (82%) create mode 100644 transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java rename transfer/src/main/java/de/juplo/kafka/payment/transfer/{persistence => domain}/TransferRepository.java (60%) rename transfer/src/main/java/de/juplo/kafka/payment/transfer/{impl/TransferServiceImpl.java => domain/TransferService.java} (75%) diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java index 49e57a3..80f1d4e 100644 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java @@ -2,7 +2,7 @@ package de.juplo.kafka.payment.transfer; import com.fasterxml.jackson.databind.ObjectMapper; -import de.juplo.kafka.payment.transfer.impl.TransferServiceImpl; +import de.juplo.kafka.payment.transfer.domain.TransferService; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerConfig; @@ -34,12 +34,12 @@ public class TransferServiceApplication } @Bean - TransferServiceImpl transferService( + TransferService transferService( KafkaProducer producer, ObjectMapper mapper, TransferServiceProperties properties) { - return new TransferServiceImpl(producer, mapper, properties.topic); + return new TransferService(producer, mapper, properties.topic); } diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/api/TransferService.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/api/TransferService.java deleted file mode 100644 index e4bb4f8..0000000 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/api/TransferService.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.juplo.kafka.payment.transfer.api; - -public interface TransferService -{ - void handleTransfer(Transfer transfer); -} diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferController.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferController.java index c93fb46..12547ef 100644 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferController.java +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferController.java @@ -1,8 +1,8 @@ package de.juplo.kafka.payment.transfer.controller; -import de.juplo.kafka.payment.transfer.api.Transfer; -import de.juplo.kafka.payment.transfer.impl.TransferServiceImpl; +import de.juplo.kafka.payment.transfer.domain.Transfer; +import de.juplo.kafka.payment.transfer.domain.TransferService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -22,16 +22,16 @@ public class TransferController { public final static String PATH = "/transfers"; - private final TransferServiceImpl service; + private final TransferService service; @PostMapping( path = PATH, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity transfer(@Valid @RequestBody Transfer transfer) + public ResponseEntity transfer(@Valid @RequestBody TransferRequest transferRequest) { - service.initiate(transfer); - return ResponseEntity.created(URI.create(PATH + transfer.getId())).build(); + service.initiate(transferRequest); + return ResponseEntity.created(URI.create(PATH + transferRequest.getId())).build(); } } diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/api/Transfer.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferRequest.java similarity index 82% rename from transfer/src/main/java/de/juplo/kafka/payment/transfer/api/Transfer.java rename to transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferRequest.java index 58ca15a..db3c781 100644 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/api/Transfer.java +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferRequest.java @@ -1,4 +1,4 @@ -package de.juplo.kafka.payment.transfer.api; +package de.juplo.kafka.payment.transfer.controller; import lombok.Data; @@ -10,7 +10,7 @@ import java.util.UUID; * Simple DTO used by the REST interface */ @Data -public class Transfer +public class TransferRequest { @NotNull(message = "Cannot be null") private UUID id; diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java new file mode 100644 index 0000000..17330f6 --- /dev/null +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java @@ -0,0 +1,23 @@ +package de.juplo.kafka.payment.transfer.domain; + + +import lombok.Data; + + +@Data +public class Transfer +{ + public enum State + { + PENDING, + APPROVED, + REJECTED + } + + private final long id; + private final long payer; + private final long payee; + private final int amount; + + private State state; +} diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/persistence/TransferRepository.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferRepository.java similarity index 60% rename from transfer/src/main/java/de/juplo/kafka/payment/transfer/persistence/TransferRepository.java rename to transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferRepository.java index 5b3d8b4..ac37192 100644 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/persistence/TransferRepository.java +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferRepository.java @@ -1,6 +1,6 @@ -package de.juplo.kafka.payment.transfer.persistence; +package de.juplo.kafka.payment.transfer.domain; -import de.juplo.kafka.payment.transfer.api.Transfer; +import de.juplo.kafka.payment.transfer.domain.Transfer; import java.util.Optional; import java.util.UUID; diff --git a/transfer/src/main/java/de/juplo/kafka/payment/transfer/impl/TransferServiceImpl.java b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferService.java similarity index 75% rename from transfer/src/main/java/de/juplo/kafka/payment/transfer/impl/TransferServiceImpl.java rename to transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferService.java index 9a24b2b..34ef29c 100644 --- a/transfer/src/main/java/de/juplo/kafka/payment/transfer/impl/TransferServiceImpl.java +++ b/transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferService.java @@ -1,34 +1,26 @@ -package de.juplo.kafka.payment.transfer.impl; +package de.juplo.kafka.payment.transfer.domain; import com.fasterxml.jackson.databind.ObjectMapper; -import de.juplo.kafka.payment.transfer.api.Transfer; -import de.juplo.kafka.payment.transfer.api.TransferService; -import de.juplo.kafka.payment.transfer.persistence.TransferRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.context.request.async.DeferredResult; -import javax.validation.Valid; import java.net.URI; import java.util.UUID; @Slf4j @RequiredArgsConstructor -public class TransferServiceImpl implements TransferService +public class TransferService { private final TransferRepository repository; private final KafkaProducer producer; private final ObjectMapper mapper; private final String topic; - - @Override public void initiate(Transfer transfer) { repository -- 2.20.1