Skip to content

Commit 2b69413

Browse files
committed
feat : 지갑을 가지지 않은 사용자 처리
1 parent 1ecaf12 commit 2b69413

7 files changed

Lines changed: 71 additions & 30 deletions

File tree

src/main/java/org/prgrms/kdtspringdemo/WebController.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ 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+
3234
model.addAttribute("customerList", customerViewDtos);
35+
model.addAttribute("customers", noneHaveWalletCustomers);
36+
3337
return "customer";
3438
}
3539

@@ -40,6 +44,13 @@ public String createCustomer(@ModelAttribute CustomerRequestDto customerRequestD
4044
return "redirect:/customers";
4145
}
4246

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

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

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

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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;
68
import org.springframework.beans.factory.annotation.Value;
79
import org.springframework.context.annotation.Profile;
810
import org.springframework.context.annotation.PropertySource;
@@ -19,6 +21,7 @@ public class FileCustomerRepository implements CustomerRepository{
1921
private CsvFileHandler csvFileHandler;
2022
@Value("${blackList_file}")
2123
private String blackListFilePath;
24+
private final Logger logger = LoggerFactory.getLogger(FileCustomerRepository.class);
2225

2326
public FileCustomerRepository() {
2427
this.csvFileHandler = new CsvFileHandler();
@@ -45,20 +48,28 @@ public List<Customer> findAll() {
4548
}
4649

4750
@Override
48-
public List<Customer> getAllBlackList() throws IOException {
49-
List<Customer> customerList = new ArrayList<>();
51+
public List<Customer> findNotHaveWalletCustomers() {
52+
return null;
53+
}
5054

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;
55+
@Override
56+
public List<Customer> getAllBlackList() {
57+
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;
5866

59-
Customer customer = new Customer(customerId, name, isBlack);
60-
customerList.add(customer);
61-
});
67+
Customer customer = new Customer(customerId, name, isBlack);
68+
customerList.add(customer);
69+
});
70+
} catch (IOException e) {
71+
logger.error(e.getMessage());
72+
}
6273
return customerList;
6374
}
6475
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ 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+
6066
@Override
6167
public void deleteAll() {
6268
jdbcTemplate.update("DELETE FROM customers");

src/main/java/org/prgrms/kdtspringdemo/wallet/service/WalletService.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
@Service
1515
public class WalletService {
1616
private final WalletRepository walletRepository;
17-
private final VoucherService voucherService;
1817

19-
public WalletService(WalletRepository walletRepository, VoucherService voucherService) {
18+
public WalletService(WalletRepository walletRepository) {
2019
this.walletRepository = walletRepository;
21-
this.voucherService = voucherService;
2220
}
2321

2422
public Wallet create(UUID customerId) {

src/main/resources/templates/customer.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ <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+
76104
</div>
77105

78106
<!-- Include Bootstrap JS -->

0 commit comments

Comments
 (0)