-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathVoucherApplication.java
More file actions
65 lines (57 loc) · 2.39 KB
/
VoucherApplication.java
File metadata and controls
65 lines (57 loc) · 2.39 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.programmers.springorder;
import org.programmers.springorder.console.Console;
import org.programmers.springorder.consts.ErrorMessage;
import org.programmers.springorder.consts.Message;
import org.programmers.springorder.customer.controller.CustomerController;
import org.programmers.springorder.utils.MenuType;
import org.programmers.springorder.voucher.controller.VoucherConsoleController;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@Profile("test")
@Component
public class VoucherApplication implements CommandLineRunner {
private final Console console;
private final VoucherConsoleController voucherConsoleController;
private final CustomerController customerController;
public VoucherApplication(Console console, VoucherConsoleController voucherConsoleController, CustomerController customerController) {
this.console = console;
this.voucherConsoleController = voucherConsoleController;
this.customerController = customerController;
}
@Override
public void run(String... args) {
boolean isRunning = true;
boolean isWeb = false;
if(chooseMedia()){
isWeb = true;
};
while(isRunning) {
if(isWeb) break;
MenuType menu = console.inputMenu();
switch (menu) {
case EXIT -> {
isRunning = false;
console.printMessage(Message.EXIT_PROGRAM_MESSAGE);
}
case CREATE -> voucherConsoleController.createVoucher();
case LIST -> voucherConsoleController.getVoucherList();
case BLACK -> customerController.printBlackList();
case ALLOCATE -> voucherConsoleController.giveVoucher();
case GET_OWNER_VOUCHER -> voucherConsoleController.getVouchersOfOwner();
case DELETE_VOUCHER -> voucherConsoleController.deleteVoucher();
case SEARCH_VOUCHER_OWNER -> customerController.getVoucherOwner();
}
}
}
private boolean chooseMedia() {
String media = console.chooseMedia();
if(media.equals("1")){
return true;
}
if(media.equals("2")){
return false;
};
throw new RuntimeException(ErrorMessage.INVALID_VALUE_MESSAGE);
}
}