-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathCustomerController.java
More file actions
59 lines (51 loc) · 2.31 KB
/
CustomerController.java
File metadata and controls
59 lines (51 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package org.prgrms.kdtspringdemo.customer.controller;
import org.prgrms.kdtspringdemo.customer.domain.Customer;
import org.prgrms.kdtspringdemo.customer.domain.dto.CustomerRequestDto;
import org.prgrms.kdtspringdemo.customer.service.CustomerService;
import org.prgrms.kdtspringdemo.view.InputConsole;
import org.prgrms.kdtspringdemo.view.OutputConsole;
import org.prgrms.kdtspringdemo.wallet.service.WalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@Controller
public class CustomerController {
private final CustomerService customerService;
private final WalletService walletService;
private final InputConsole inputConsole = new InputConsole();
private final OutputConsole outputConsole = new OutputConsole();
private final Logger logger = LoggerFactory.getLogger(CustomerController.class);
public CustomerController(CustomerService customerService, WalletService walletService) {
this.customerService = customerService;
this.walletService = walletService;
}
public void insert() {
try {
UUID customerId = UUID.randomUUID();
outputConsole.getCustomerName();
String name = inputConsole.getString();
outputConsole.getCustomerIsBlack();
Boolean isBlack = Boolean.parseBoolean(inputConsole.getString());
customerService.insert(new CustomerRequestDto(name, isBlack));
walletService.create(customerId); // 고객 생성 시 지갑 자동 생성
} catch (IOException e) {
logger.error(e.getMessage());
} catch (IllegalArgumentException e) {
logger.error("유효한 UUID 값이 아닙니다.");
}
}
public void printAllCustomers() {
List<Customer> customerList = customerService.findAll();
customerList.stream().forEach(customer -> outputConsole.printCustomer(customer));
}
public void printAllBlackListCustomer() throws IOException {
List<Customer> customerList = customerService.getBlackListCustomers();
customerList.stream().forEach(customer -> outputConsole.printCustomer(customer));
}
public void endCustomerMode() {
outputConsole.printCustomerModeEnd();
}
}