1 package de.aikiit.bilanzanalyser.entity.database;
2
3 import de.aikiit.bilanzanalyser.entity.database.repository.PaymentRepository;
4 import de.aikiit.bilanzanalyser.entity.database.repository.SourceRepository;
5 import org.springframework.boot.CommandLineRunner;
6 import org.springframework.context.annotation.Bean;
7 import org.springframework.context.annotation.Configuration;
8
9 import java.util.List;
10
11 @Configuration
12 public class DataInitializer {
13
14 @Bean
15 CommandLineRunner initData(PaymentRepository paymentRepository, SourceRepository sourceRepository) {
16 return args -> {
17
18
19 for (String category : List.of("KK", "Bar", "EC", "Überwiesen")) {
20 paymentRepository.findByName(category).orElseGet(() -> {
21 PaymentEntity payment = new PaymentEntity();
22 payment.setName(category);
23 return paymentRepository.save(payment);
24 });
25 }
26
27
28 for (String source : List.of("Ausgaben", "Einnahmen")) {
29 sourceRepository.findByName(source).orElseGet(() -> {
30 SourceEntity sourceEntity = new SourceEntity();
31 sourceEntity.setName(source);
32 return sourceRepository.save(sourceEntity);
33 });
34 }
35 };
36 }
37 }