Skip to content
Snippets Groups Projects
Commit 350a7379 authored by Filip Kollár's avatar Filip Kollár Committed by Filip Fabry
Browse files

added sequence generation of account numbers

parent 69dca455
No related branches found
No related tags found
1 merge request!40added sequence generation of account numbers
package cz.muni.fi.obs.data;
import cz.muni.fi.obs.api.TransactionCreateDto;
import cz.muni.fi.obs.data.dbo.AccountDbo;
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.service.TransactionService;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@ConditionalOnExpression("${data.initialize:false}")
@Slf4j
public class TransactionServiceDataSeeder {
private final ScheduledPaymentRepository scheduledPaymentRepository;
private final TransactionRepository transactionRepository;
private final AccountRepository accountRepository;
private final TransactionService transactionService;
@Autowired
public TransactionServiceDataSeeder(AccountRepository accountRepository,
TransactionRepository transactionRepository,
ScheduledPaymentRepository scheduledPaymentRepository, TransactionService transactionService) {
this.accountRepository = accountRepository;
this.transactionRepository = transactionRepository;
this.scheduledPaymentRepository = scheduledPaymentRepository;
this.transactionService = transactionService;
}
@PostConstruct
public void initializeData() {
log.info("Initializing transaction service data...");
List<AccountDbo> accounts = createAccounts();
createScheduledPayments(accounts);
transactionService
createTransactions(accounts);
log.info("Initialized transaction service data...");
}
// TODO: implement
private void createTransactions(List<AccountDbo> accounts) {
TransactionCreateDto transactionCreateDto = new TransactionCreateDto();
transactionService.createTransaction(transactionCreateDto)
}
private List<AccountDbo> createAccounts() {
AccountDbo accountDbo = new AccountDbo();
accountRepository.save(accountDbo)
}
private void createScheduledPayments(List<AccountDbo> accounts) {
}
}
package cz.muni.fi.obs.data.dbo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
......@@ -27,6 +31,14 @@ public class AccountDbo {
private String customerId;
@Column(name = "currency_code", nullable = false)
private String currencyCode;
@GeneratedValue
@SequenceGenerator(name = "account_number_sequence", allocationSize = 1)
@Column(name = "account_number", nullable = false, unique = true)
private String accountNumber;
@JsonIgnore
private Integer accountNumber;
@Transient
private String getAccountNumber() {
return String.format("%08d", accountNumber);
}
}
ALTER TABLE accounts
ALTER COLUMN account_number SET DATA TYPE numeric(38, 0);
CREATE SEQUENCE account_number_sequence START 1;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment