Configure H2 database and add repositories
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package net.kapcake.bankingservice.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.h2.tools.Server;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@Configuration
|
||||
public class BankingServiceConfig {
|
||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||
public Server h2Server() throws SQLException {
|
||||
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "BANKING_USER")
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.Address;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface AddressRepository extends JpaRepository<Address, Long> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.BankAccount;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface BankAccountRepository extends JpaRepository<BankAccount, Long> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.Payment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
9
src/main/resources/application.yml
Normal file
9
src/main/resources/application.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
|
||||
driver-class-name: org.h2.Driver
|
||||
username: bank
|
||||
password: bankPassword
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
defer-datasource-initialization: true
|
||||
5
src/main/resources/data.sql
Normal file
5
src/main/resources/data.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
INSERT INTO ADDRESS (id, street, number, postal_code, country)
|
||||
values (1, 'street', 1, 9999, 'Luxembourg');
|
||||
|
||||
INSERT INTO BANKING_USER (id, username, password, address_id)
|
||||
values (1, 'user1', 'test', 1);
|
||||
Reference in New Issue
Block a user