Skip to content

Commit 1ecaf12

Browse files
committed
feat : customer 생성 삭제 기능 컨트롤러 연결
1 parent a4ac945 commit 1ecaf12

6 files changed

Lines changed: 22 additions & 79 deletions

File tree

src/main/java/org/prgrms/kdtspringdemo/customer/controller/CustomerWebController.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ public String getAllCustomers(Model model) {
2929
List<Customer> customerList = customerService.findAll();
3030
List<CustomerViewDto> customerViewDtos = new ArrayList<>();
3131
customerList.stream().forEach(customer -> customerViewDtos.add(new CustomerViewDto(customer)));
32-
List<Customer> noneHaveWalletCustomers = customerService.findNoneHaveWalletCustomer();
33-
3432
model.addAttribute("customerList", customerViewDtos);
35-
model.addAttribute("customers", noneHaveWalletCustomers);
36-
3733
return "customer";
3834
}
3935

@@ -44,13 +40,6 @@ public String createCustomer(@ModelAttribute CustomerRequestDto customerRequestD
4440
return "redirect:/customers";
4541
}
4642

47-
@GetMapping("/{customerId}/createWallet")
48-
public String createWalletForCustomer(@PathVariable UUID customerId) {
49-
walletService.create(customerId);
50-
return "redirect:/customers";
51-
}
52-
53-
5443
@GetMapping("/{customerId}/delete")
5544
public String deleteVoucher(@PathVariable UUID customerId) {
5645
customerService.deleteById(customerId);

src/main/java/org/prgrms/kdtspringdemo/customer/repository/CustomerRepository.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ public interface CustomerRepository {
1212
void deleteAll();
1313
void deleteById(UUID customerId);
1414
List<Customer> findAll();
15-
List<Customer> findNotHaveWalletCustomers();
16-
List<Customer> getAllBlackList();
15+
List<Customer> getAllBlackList() throws IOException;
1716
}

src/main/java/org/prgrms/kdtspringdemo/customer/repository/FileCustomerRepository.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import org.apache.commons.csv.CSVRecord;
44
import org.prgrms.kdtspringdemo.customer.domain.Customer;
55
import org.prgrms.kdtspringdemo.file.CsvFileHandler;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
86
import org.springframework.beans.factory.annotation.Value;
97
import org.springframework.context.annotation.Profile;
108
import org.springframework.context.annotation.PropertySource;
@@ -21,7 +19,6 @@ public class FileCustomerRepository implements CustomerRepository{
2119
private CsvFileHandler csvFileHandler;
2220
@Value("${blackList_file}")
2321
private String blackListFilePath;
24-
private final Logger logger = LoggerFactory.getLogger(FileCustomerRepository.class);
2522

2623
public FileCustomerRepository() {
2724
this.csvFileHandler = new CsvFileHandler();
@@ -48,28 +45,20 @@ public List<Customer> findAll() {
4845
}
4946

5047
@Override
51-
public List<Customer> findNotHaveWalletCustomers() {
52-
return null;
53-
}
54-
55-
@Override
56-
public List<Customer> getAllBlackList() {
48+
public List<Customer> getAllBlackList() throws IOException {
5749
List<Customer> customerList = new ArrayList<>();
58-
try {
59-
List<CSVRecord> data = csvFileHandler.readCSV(blackListFilePath);
60-
data.stream()
61-
.filter(line -> line.get("isBlack").equals("true"))
62-
.forEach(line -> {
63-
UUID customerId = UUID.fromString(line.get("customerId"));
64-
String name = line.get("name");
65-
boolean isBlack = true;
6650

67-
Customer customer = new Customer(customerId, name, isBlack);
68-
customerList.add(customer);
69-
});
70-
} catch (IOException e) {
71-
logger.error(e.getMessage());
72-
}
51+
List<CSVRecord> data = csvFileHandler.readCSV(blackListFilePath);
52+
data.stream()
53+
.filter(line -> line.get("isBlack").equals("true"))
54+
.forEach(line -> {
55+
UUID customerId = UUID.fromString(line.get("customerId"));
56+
String name = line.get("name");
57+
boolean isBlack = true;
58+
59+
Customer customer = new Customer(customerId, name, isBlack);
60+
customerList.add(customer);
61+
});
7362
return customerList;
7463
}
7564
}

src/main/java/org/prgrms/kdtspringdemo/customer/repository/JdbcCustomerRepository.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ public List<Customer> findAll() {
5757
return jdbcTemplate.query("select * from customers", customerRowMapper);
5858
}
5959

60-
@Override
61-
public List<Customer> findNotHaveWalletCustomers() {
62-
return jdbcTemplate.query("SELECT c.customer_id, c.name, c.is_black FROM customers c LEFT JOIN wallet w ON c.customer_id = w.customer_id WHERE w.customer_id IS NULL",
63-
customerRowMapper);
64-
}
65-
6660
@Override
6761
public void deleteAll() {
6862
jdbcTemplate.update("DELETE FROM customers");

src/main/java/org/prgrms/kdtspringdemo/wallet/repository/JdbcWalletRepository.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public JdbcWalletRepository(DataSource dataSource) {
6363
@Override
6464
public Wallet insert(Wallet wallet) {
6565
var update = jdbcTemplate.update("INSERT INTO wallet(wallet_id, customer_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?))",
66-
wallet.getWalletId(),
67-
wallet.getCustomerId());
66+
wallet.getWalletId().toString(),
67+
wallet.getCustomerId().toString());
6868
if(update != 1) {
6969
throw new RuntimeException("Nothing was inserted");
7070
}
@@ -76,7 +76,7 @@ public Optional<Wallet> findById(UUID walletId) {
7676
try {
7777
return Optional.ofNullable(jdbcTemplate.queryForObject("select * from wallet WHERE wallet_id = UUID_TO_BIN(?)",
7878
walletRowMapper,
79-
walletId.toString().getBytes()));
79+
walletId.toString()));
8080
} catch (EmptyResultDataAccessException e) {
8181
logger.error("Got empty result", e);
8282
return Optional.empty();
@@ -99,8 +99,8 @@ public List<Voucher> findVouchersByCustomerId(UUID customerId) {
9999
@Override
100100
public void deleteVoucherByVoucherId(UUID customerId, UUID voucherId) {
101101
var update = jdbcTemplate.update("DELETE from wallet_customer_voucher WHERE customer_id = UUID_TO_BIN(?) and voucher_id = UUID_TO_BIN(?)",
102-
customerId.toString().getBytes(),
103-
voucherId.toString().getBytes());
102+
customerId.toString(),
103+
voucherId.toString());
104104
if(update != 1) {
105105
throw new RuntimeException("Nothing was deleted");
106106
}
@@ -111,7 +111,7 @@ public Optional<Customer> findCustomerByVoucherId(UUID voucherId) {
111111
return Optional.ofNullable(jdbcTemplate.queryForObject("select c.customer_id, c.name, c.is_black from customers c inner join wallet_customer_voucher inter" +
112112
"on c.customer_id = inter.customer_id where inter.voucher_id = UUID_TO_BIN(?)",
113113
customerRowMapper,
114-
voucherId.toString().getBytes()));
114+
voucherId.toString()));
115115
}
116116

117117
@Override
@@ -123,9 +123,9 @@ public void deleteById(UUID walletId) {
123123
@Override
124124
public void addVoucherByCustomerId(UUID walletId, UUID customerId, UUID voucherId) {
125125
var update = jdbcTemplate.update("INSERT INTO wallet_customer_voucher(wallet_id, customer_id, voucher_id) VALUES (UUID_TO_BIN(?), UUID_TO_BIN(?), UUID_TO_BIN(?))",
126-
walletId.toString().getBytes(),
127-
customerId.toString().getBytes(),
128-
voucherId.toString().getBytes());
126+
walletId.toString(),
127+
customerId.toString(),
128+
voucherId.toString());
129129
if(update != 1) {
130130
throw new RuntimeException("Nothing was inserted");
131131
}

src/main/resources/templates/customer.html

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,34 +73,6 @@ <h2 class="mt-5">Add Customer</h2>
7373
<button type="submit" class="btn btn-primary">Add Customer</button>
7474
</form>
7575

76-
<!--None Have Wallet Customers-->
77-
<h2 class="mt-5">Customers : None Have Wallet</h2>
78-
<table class="table">
79-
<thead class="thead-dark">
80-
<tr>
81-
<th>Customer ID</th>
82-
<th>Name</th>
83-
<th>Is Black</th>
84-
<th>Action</th>
85-
</tr>
86-
</thead>
87-
<tbody>
88-
<th:block th:each="customer : ${customers}">
89-
<tr>
90-
<td th:text="${customer.customerId}">Customer ID</td>
91-
<td th:text="${customer.name}">Name</td>
92-
<td th:text="${customer.isBlack}">Is Black</td>
93-
<td>
94-
<a th:href="@{'/customers/' + ${customer.customerId} + '/createWallet'}">
95-
<button class="btn btn-primary">Create Wallet</button>
96-
</a>
97-
</td>
98-
</tr>
99-
</th:block>
100-
</tbody>
101-
</table>
102-
103-
10476
</div>
10577

10678
<!-- Include Bootstrap JS -->

0 commit comments

Comments
 (0)