Skip to content

Commit 35919e3

Browse files
committed
enhance: set unique value(voucher_id) at wallet table
1 parent 346d6aa commit 35919e3

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

src/main/resources/schema.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ CREATE TABLE vouchers
1414
created_at datetime(6) DEFAULT CURRENT_TIMESTAMP(6)
1515
);
1616

17-
CREATE TABLE voucher_customer_own_info
17+
CREATE TABLE wallet
1818
(
1919
id INT PRIMARY KEY AUTO_INCREMENT,
2020
customer_id BINARY(16) NOT NULL REFERENCES customers (id) ON DELETE CASCADE,
21-
voucher_id BINARY(16) NOT NULL REFERENCES vouchers (id) ON DELETE CASCADE
21+
voucher_id BINARY(16) NOT NULL REFERENCES vouchers (id) ON DELETE CASCADE,
22+
CONSTRAINT voucher_id UNIQUE (voucher_id)
2223
);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.programmers.vouchermanagement.wallet;
2+
3+
import com.programmers.vouchermanagement.wallet.repository.WalletJDBCRepository;
4+
import com.zaxxer.hikari.HikariDataSource;
5+
import org.junit.jupiter.api.*;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.jdbc.DataSourceBuilder;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.ComponentScan;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.jdbc.core.JdbcTemplate;
12+
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
13+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
14+
15+
import javax.sql.DataSource;
16+
17+
@SpringJUnitConfig
18+
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
19+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
20+
class WalletJDBCRepositoryTest {
21+
@Autowired
22+
WalletJDBCRepository walletJDBCRepository;
23+
@Autowired
24+
DataSource dataSource;
25+
26+
@Test
27+
@DisplayName("고객 id와 바우처 id 정보를 함께 저장할 수 있다.")
28+
void save() {
29+
}
30+
31+
@Test
32+
@DisplayName("고객 id로 고객이 가진 바우처 id를 가져올 수 있다.")
33+
void findAllVoucherByCustomerId() {
34+
}
35+
36+
@Test
37+
@DisplayName("함께 저장된 고객 id와 바우처 id 정보를 삭제할 수 있다.")
38+
void delete() {
39+
}
40+
41+
@Test
42+
@DisplayName("바우처 id로 바우처를 가진 고객 id를 가져올 수 있다.")
43+
void findCustomerByVoucherId() {
44+
}
45+
46+
@Configuration
47+
@ComponentScan(
48+
basePackages = {"com.programmers.vouchermanagement.wallet.repository"}
49+
)
50+
static class Config {
51+
@Bean
52+
public DataSource dataSource() {
53+
var dataSource = DataSourceBuilder.create()
54+
.url("jdbc:mysql://localhost:3306/test")
55+
.username("root")
56+
.password("980726")
57+
.type(HikariDataSource.class)
58+
.build();
59+
dataSource.setMaximumPoolSize(1000);
60+
dataSource.setMinimumIdle(100);
61+
return dataSource;
62+
}
63+
64+
@Bean
65+
public JdbcTemplate jdbcTemplate(DataSource dataSource) {
66+
return new JdbcTemplate(dataSource);
67+
}
68+
69+
@Bean
70+
public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) {
71+
return new NamedParameterJdbcTemplate(jdbcTemplate);
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)