diff --git a/transaction-service/src/main/java/cz/muni/fi/obs/data/TransactionServiceDataSeeder.java b/transaction-service/src/main/java/cz/muni/fi/obs/data/TransactionServiceDataSeeder.java index b6804d778fdaa136398a1780c574959a2c4eb7be..04767b23e5e82381bc987d3d3e0d5ff7cd43794f 100644 --- a/transaction-service/src/main/java/cz/muni/fi/obs/data/TransactionServiceDataSeeder.java +++ b/transaction-service/src/main/java/cz/muni/fi/obs/data/TransactionServiceDataSeeder.java @@ -1,21 +1,25 @@ package cz.muni.fi.obs.data; +import cz.muni.fi.obs.api.ScheduledPaymentCreateDto; import cz.muni.fi.obs.api.TransactionCreateDto; import cz.muni.fi.obs.data.dbo.AccountDbo; +import cz.muni.fi.obs.data.dbo.PaymentFrequency; import cz.muni.fi.obs.data.repository.AccountRepository; import cz.muni.fi.obs.data.repository.ScheduledPaymentRepository; import cz.muni.fi.obs.data.repository.TransactionRepository; +import cz.muni.fi.obs.facade.TransactionManagementFacade; import cz.muni.fi.obs.service.TransactionService; -import cz.muni.fi.obs.util.JsonConvertor; +import cz.muni.fi.obs.service.payment.ScheduledPaymentService; import cz.muni.fi.obs.util.Resources; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; -import org.flywaydb.core.internal.util.JsonUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.stereotype.Component; +import java.math.BigDecimal; +import java.time.LocalDate; import java.util.List; import com.fasterxml.jackson.core.type.TypeReference; @@ -25,19 +29,20 @@ import com.fasterxml.jackson.core.type.TypeReference; @Slf4j public class TransactionServiceDataSeeder { - private final ScheduledPaymentRepository scheduledPaymentRepository; - private final TransactionRepository transactionRepository; private final AccountRepository accountRepository; - private final TransactionService transactionService; + private final ScheduledPaymentService scheduledPaymentService; + private final TransactionManagementFacade transactionManagementFacade; @Autowired public TransactionServiceDataSeeder(AccountRepository accountRepository, TransactionRepository transactionRepository, - ScheduledPaymentRepository scheduledPaymentRepository, TransactionService transactionService) { + ScheduledPaymentRepository scheduledPaymentRepository, + TransactionService transactionService, + ScheduledPaymentService scheduledPaymentService, + TransactionManagementFacade transactionManagementFacade) { this.accountRepository = accountRepository; - this.transactionRepository = transactionRepository; - this.scheduledPaymentRepository = scheduledPaymentRepository; - this.transactionService = transactionService; + this.scheduledPaymentService = scheduledPaymentService; + this.transactionManagementFacade = transactionManagementFacade; } @PostConstruct @@ -45,11 +50,34 @@ public class TransactionServiceDataSeeder { log.info("Initializing transaction service data..."); List<AccountDbo> accounts = createAccounts(); + createTransactions(accounts); + createScheduledPayments(accounts); log.info("Initialized transaction service data..."); } private void createTransactions(List<AccountDbo> accounts) { + transactionManagementFacade.createTransaction(new TransactionCreateDto( + accounts.get(0).getId(), + accounts.getLast().getId(), + new BigDecimal(10000), + "Test transaction 1", + "123456" + )); + transactionManagementFacade.createTransaction(new TransactionCreateDto( + accounts.get(2).getId(), + accounts.get(3).getId(), + new BigDecimal(20000), + "Test transaction 2", + "654321" + )); + transactionManagementFacade.createTransaction(new TransactionCreateDto( + accounts.get(3).getId(), + accounts.get(4).getId(), + new BigDecimal(30000), + "Test transaction 3", + "987654" + )); } private List<AccountDbo> createAccounts() { @@ -62,5 +90,26 @@ public class TransactionServiceDataSeeder { } private void createScheduledPayments(List<AccountDbo> accounts) { + scheduledPaymentService.createPayment(new ScheduledPaymentCreateDto( + LocalDate.of(2024, 6, 6), + null, + PaymentFrequency.YEARLY, + accounts.getFirst().getId(), + accounts.getLast().getId() + )); + scheduledPaymentService.createPayment(new ScheduledPaymentCreateDto( + LocalDate.of(2024, 7, 7), + null, + PaymentFrequency.MONTHLY, + accounts.get(1).getId(), + accounts.get(2).getId() + )); + scheduledPaymentService.createPayment(new ScheduledPaymentCreateDto( + LocalDate.of(2024, 8, 8), + null, + PaymentFrequency.WEEKLY, + accounts.get(3).getId(), + accounts.get(4).getId() + )); } }