WIP
authorKai Moritz <kai@juplo.de>
Fri, 11 Jun 2021 16:17:38 +0000 (18:17 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 11 Jun 2021 16:17:38 +0000 (18:17 +0200)
transfer/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferController.java
transfer/src/main/java/de/juplo/kafka/payment/transfer/controller/TransferRequest.java
transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/Transfer.java
transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferRepository.java
transfer/src/main/java/de/juplo/kafka/payment/transfer/domain/TransferService.java

index 80f1d4e..cc3e056 100644 (file)
@@ -2,6 +2,7 @@ package de.juplo.kafka.payment.transfer;
 
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import de.juplo.kafka.payment.transfer.domain.TransferRepository;
 import de.juplo.kafka.payment.transfer.domain.TransferService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.producer.KafkaProducer;
@@ -35,11 +36,12 @@ public class TransferServiceApplication
 
   @Bean
   TransferService transferService(
+      TransferRepository repository,
       KafkaProducer<UUID, String> producer,
       ObjectMapper mapper,
       TransferServiceProperties properties)
   {
-    return new TransferService(producer, mapper, properties.topic);
+    return new TransferService(repository, producer, mapper, properties.topic);
   }
 
 
index 12547ef..d8dcc83 100644 (file)
@@ -31,7 +31,17 @@ public class TransferController
       produces = MediaType.APPLICATION_JSON_VALUE)
   public ResponseEntity<?> transfer(@Valid @RequestBody TransferRequest transferRequest)
   {
-    service.initiate(transferRequest);
+    Transfer transfer =
+        Transfer
+            .builder()
+            .id(transferRequest.getId())
+            .payer(transferRequest.getPayer())
+            .payee(transferRequest.getPayee())
+            .amount(transferRequest.getAmount())
+            .build();
+
+    service.initiate(transfer);
+
     return ResponseEntity.created(URI.create(PATH + transferRequest.getId())).build();
   }
 }
index db3c781..43b4f90 100644 (file)
@@ -3,7 +3,6 @@ package de.juplo.kafka.payment.transfer.controller;
 import lombok.Data;
 
 import javax.validation.constraints.NotNull;
-import java.util.UUID;
 
 
 /**
@@ -13,7 +12,7 @@ import java.util.UUID;
 public class TransferRequest
 {
   @NotNull(message = "Cannot be null")
-  private UUID id;
+  private long id;
   @NotNull(message = "Cannot be null")
   private long payer;
   @NotNull(message = "Cannot be null")
index 17330f6..2aa87fe 100644 (file)
@@ -1,14 +1,18 @@
 package de.juplo.kafka.payment.transfer.domain;
 
 
+import lombok.Builder;
 import lombok.Data;
 
 
 @Data
+@Builder
 public class Transfer
 {
   public enum State
   {
+    CREATED,
+    FAILED,
     PENDING,
     APPROVED,
     REJECTED
index ac37192..908caa1 100644 (file)
@@ -9,5 +9,5 @@ import java.util.UUID;
 public interface TransferRepository
 {
   void put(Transfer transfer);
-  Optional<Transfer> get(UUID uuid);
+  Optional<Transfer> get(Long id);
 }
index 34ef29c..6545e29 100644 (file)
@@ -21,19 +21,26 @@ public class TransferService
   private final ObjectMapper mapper;
   private final String topic;
 
-  public void initiate(Transfer transfer)
+  public synchronized void initiate(Transfer transfer)
   {
     repository
         .get(transfer.getId())
         .ifPresentOrElse(
             stored ->
             {
-
+              switch (stored.getState())
+              {
+                case FAILED:
+              }
             },
             () ->
             {
-
             });
+  }
+
+
+  private void create(Transfer transfer)
+  {
     try
     {
       ProducerRecord<UUID, String> record =