-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathWalletController.java
More file actions
65 lines (56 loc) · 2.8 KB
/
WalletController.java
File metadata and controls
65 lines (56 loc) · 2.8 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
60
61
62
63
64
65
package org.prgms.kdtspringweek1.controller.consoleController;
import org.prgms.kdtspringweek1.console.ConsoleOutput;
import org.prgms.kdtspringweek1.controller.consoleController.dto.SelectFunctionTypeDto;
import org.prgms.kdtspringweek1.customer.service.dto.FindCustomerResponseDto;
import org.prgms.kdtspringweek1.voucher.service.dto.FindVoucherResponseDto;
import org.prgms.kdtspringweek1.wallet.entity.Wallet;
import org.prgms.kdtspringweek1.wallet.service.WalletService;
import org.springframework.stereotype.Component;
import java.util.UUID;
@Component
public class WalletController {
private final ConsoleInputConverter consoleInputConverter;
private final ConsoleOutput consoleOutput;
private final WalletService walletService;
public WalletController(ConsoleInputConverter consoleInputConverter, ConsoleOutput consoleOutput, WalletService walletService) {
this.consoleInputConverter = consoleInputConverter;
this.consoleOutput = consoleOutput;
this.walletService = walletService;
}
public void selectVoucherFunction(SelectFunctionTypeDto functionTypeDto) {
switch (functionTypeDto) {
case CREATE_MY_WALLET -> createWallet();
case SEARCH_MY_VOUCHERS -> getAllVouchersOwnedByCustomer();
case DELETE_MY_WALLET -> deleteWallet();
case SEARCH_MY_CUSTOMERS -> getAllCustomersOwnedByVoucher();
}
}
private void createWallet() {
consoleOutput.printRequestMessageForCustomerId();
UUID customerId = consoleInputConverter.getId();
consoleOutput.printRequestMessageForVoucherId();
UUID voucherId = consoleInputConverter.getId();
walletService.registerWallet(Wallet.createWithVoucherIdAndCustomerId(voucherId, customerId));
consoleOutput.printSuccessToCreate();
}
private void getAllVouchersOwnedByCustomer() {
consoleOutput.printRequestMessageForCustomerId();
walletService.searchAllVouchersByCustomerId(consoleInputConverter.getId())
.forEach(FindVoucherResponseDto::printVoucherInfo);
consoleOutput.printSuccessToSearch();
}
private void deleteWallet() {
consoleOutput.printRequestMessageForCustomerId();
UUID customerId = consoleInputConverter.getId();
consoleOutput.printRequestMessageForVoucherId();
UUID voucherId = consoleInputConverter.getId();
walletService.deleteWalletByVoucherIdAndCustomerId(voucherId, customerId);
consoleOutput.printSuccessToDelete();
}
private void getAllCustomersOwnedByVoucher() {
consoleOutput.printRequestMessageForVoucherId();
walletService.searchAllCustomersByVoucherId(consoleInputConverter.getId())
.forEach(FindCustomerResponseDto::printCustomerInfo);
consoleOutput.printSuccessToSearch();
}
}