From 31811b205d14ef9c258260a3366af80ae552b237 Mon Sep 17 00:00:00 2001 From: Pavel <xtetauer@fi.muni.cz> Date: Tue, 7 May 2024 13:37:24 +0200 Subject: [PATCH] Added seeding data --- .../data/TransactionServiceDataSeeder.java | 67 ++++++++++++++++--- 1 file changed, 58 insertions(+), 9 deletions(-) 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 b6804d7..04767b2 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() + )); } } -- GitLab