1 package de.juplo.kafka.payment.transfer.ports;
4 import de.juplo.kafka.payment.transfer.domain.Transfer;
5 import lombok.RequiredArgsConstructor;
6 import lombok.extern.slf4j.Slf4j;
8 import java.util.Optional;
10 import static de.juplo.kafka.payment.transfer.domain.Transfer.State.CHECKED;
11 import static de.juplo.kafka.payment.transfer.domain.Transfer.State.CREATED;
15 @RequiredArgsConstructor
16 public class TransferService implements CreateTransferUseCase, HandleStateChangeUseCase, GetTransferUseCase
18 private final TransferRepository repository;
19 private final MessagingService messagingService;
22 public void create(Long id, Long payer, Long payee, Integer amount)
28 "transfer already exisits: {}, ignoring: id={}, payer={}, payee={}, amount={}",
44 log.info("creating transfer: {}", transfer);
45 repository.store(transfer);
46 messagingService.send(transfer.getId(), CREATED);
51 public void handleStateChange(Long id, Transfer.State state)
61 transfer.setState(CREATED);
62 repository.store(transfer);
68 transfer.setState(CHECKED);
69 repository.store(transfer);
70 // TODO: What's next...?
75 log.warn("TODO: handle {} state {}", state.foreign ? "foreign" : "domain", state);
78 () -> log.error("unknown transfer: {}", id));
81 private void check(Transfer transfer)
83 // TODO: Do some time consuming checks...
84 messagingService.send(transfer.getId(), CHECKED);
87 public Optional<Transfer> get(Long id)
89 return repository.get(id);