1
1
package com .sprint .mission .discodeit ;
2
2
3
- import com .sprint .mission .discodeit .entity . Channel ;
4
- import com .sprint .mission .discodeit .entity . Message ;
5
- import com .sprint .mission .discodeit .entity . User ;
3
+ import com .sprint .mission .discodeit .menu . ChannelMenu ;
4
+ import com .sprint .mission .discodeit .menu . MessageMenu ;
5
+ import com .sprint .mission .discodeit .menu . UserMenu ;
6
6
import com .sprint .mission .discodeit .service .jcf .JCFChannelService ;
7
7
import com .sprint .mission .discodeit .service .jcf .JCFMessageService ;
8
8
import com .sprint .mission .discodeit .service .jcf .JCFUserService ;
9
9
10
10
import java .util .Scanner ;
11
- import java .util .UUID ;
12
11
13
12
public class JavaApplication {
14
13
public static void main (String [] args ) {
@@ -21,207 +20,35 @@ public static void main(String[] args) {
21
20
userService .addChannelService (channelService );
22
21
23
22
while (true ) {
24
- System .out .println ("===== MAIN MENU =====" );
23
+ System .out .println ("\n ===== MAIN MENU =====" );
25
24
System .out .println ("1. 사용자 메뉴" );
26
25
System .out .println ("2. 채널 메뉴" );
27
26
System .out .println ("3. 메시지 메뉴" );
28
27
System .out .println ("0. 종료" );
29
- System .out .println ("번호를 입력하세요" );
30
- String mainMenu = scanner .nextLine ();
31
-
32
- switch (mainMenu ) {
33
- case "1" :
34
- userMenu (scanner , userService );
35
- break ;
36
- case "2" :
37
- channelMenu (scanner , channelService , userService );
38
- break ;
39
- case "3" :
40
- messageMenu (scanner , messageService , channelService , userService );
41
- break ;
42
- case "0" :
43
- System .out .println ("종료" );
44
- return ;
45
- default :
46
- System .out .println ("표시되지 않은 번호를 눌렀습니다" );
47
- }
48
- }
49
- }
50
-
51
- private static void userMenu (Scanner scanner , JCFUserService userService ) {
52
- while (true ) {
53
- System .out .println ("===== USER MENU =====" );
54
- System .out .println ("1. 사용자 등록" );
55
- System .out .println ("2. 사용자 단건 조회" );
56
- System .out .println ("3. 사용자 다건 조회" );
57
- System .out .println ("4. 사용자 수정" );
58
- System .out .println ("5. 사용자 삭제" );
59
- System .out .println ("0. 초기 화면으로" );
60
- System .out .println ("번호를 입력하세요" );
61
- String select = scanner .nextLine ();
62
-
63
- switch (select ) {
64
- case "1" :
65
- System .out .println ("사용자 이름 입력" );
66
- String userName = scanner .nextLine ();
67
- User user = new User (userName );
68
- userService .createUser (user );
69
- System .out .println ("생성된 사용자 식별키 : " + user .getId ());
70
- break ;
71
- case "2" :
72
- System .out .println ("조회할 사용자의 식별키 입력" );
73
- UUID id = UUID .fromString (scanner .nextLine ());
74
- User userId = userService .getUser (id );
75
- if (userId != null ) {
76
- System .out .println ("사용자 이름 : " + userId .getUserName ());
77
- } else {
78
- System .out .println ("해당 식별키를 가진 사용자가 없습니다" );
79
- }
80
- break ;
81
- case "3" :
82
- System .out .println ("전체 사용자 목록" );
83
- userService .getAllUsers ()
84
- .forEach (u -> System .out .println (u .getId ()
85
- + " - " + u .getUserName ()));
86
- case "4" :
87
- System .out .println ("수정할 사용자 식별키 입력" );
88
- UUID updateId = UUID .fromString (scanner .nextLine ());
89
- System .out .println ("새로운 사용자 이름 입력" );
90
- String newUserName = scanner .nextLine ();
91
- userService .updateUser (updateId , newUserName );
92
- System .out .println ("수정 완료" );
93
- break ;
94
- case "5" :
95
- System .out .println ("삭제할 사용자 식별키 입력" );
96
- UUID deleteId = UUID .fromString (scanner .nextLine ());
97
- userService .deleteUser (deleteId );
98
- System .out .println ("삭제 완료" );
99
- break ;
100
- case "0" :
101
- return ;
102
- default :
103
- System .out .println ("표시되지 않은 번호를 눌렀습니다" );
104
- }
105
- }
106
- }
107
-
108
- private static void channelMenu (Scanner scanner , JCFChannelService channelService , JCFUserService userService ) {
109
- while (true ) {
110
- System .out .println ("===== CHANNEL MENU =====" );
111
- System .out .println ("1. 채널 생성" );
112
- System .out .println ("2. 채널 단건 조회" );
113
- System .out .println ("3. 채널 다건 조회" );
114
- System .out .println ("4. 채널 수정" );
115
- System .out .println ("5. 채널 삭제" );
116
- System .out .println ("6. 채널에 사용자 추가" );
117
- System .out .println ("0. 초기 화면으로" );
118
- System .out .println ("번호를 입력하세요" );
119
- String select = scanner .nextLine ();
120
-
121
- switch (select ) {
122
- case "1" :
123
- System .out .println ("채널 이름 입력" );
124
- String channelName = scanner .nextLine ();
125
- Channel channel = new Channel (channelName );
126
- channelService .createChannel (channel );
127
- System .out .println ("생성된 채널 식별키 : " + channel .getId ());
128
- break ;
129
- case "2" :
130
- System .out .println ("조회할 채널 식별키 입력" );
131
- UUID channelId = UUID .fromString (scanner .nextLine ());
132
- Channel find = channelService .getChannel (channelId );
133
- if (find != null ) {
134
- System .out .println ("채널 이름 : " + find .getChannelName ());
135
- System .out .println ("참가자 : " + find .getUserIds ());
136
- } else {
137
- System .out .println ("해당 식별키를 가진 채널이 없습니다" );
138
- }
139
- break ;
140
- case "3" :
141
- channelService .getAllChannels ()
142
- .forEach (ch -> System .out .println (ch .getId ()
143
- + " - " + ch .getChannelName ()));
144
- break ;
145
- case "4" :
146
- System .out .println ("수정할 채널 식별키 입력" );
147
- UUID updateCh = UUID .fromString (scanner .nextLine ());
148
- System .out .println ("새로운 채널 이름 입력" );
149
- String newChannelName = scanner .nextLine ();
150
- channelService .updateChannel (updateCh , newChannelName );
151
- break ;
152
- case "5" :
153
- System .out .println ("삭제할 채널 식별키 입력" );
154
- UUID deleteCh = UUID .fromString (scanner .nextLine ());
155
- channelService .deleteChannel (deleteCh );
156
- break ;
157
- case "6" :
158
- System .out .println ("채널 식별키 입력" );
159
- UUID joinCh = UUID .fromString (scanner .nextLine ());
160
- System .out .println ("등록할 사용자 식별키 입력" );
161
- UUID userJoin = UUID .fromString (scanner .nextLine ());
162
- channelService .addUserToChannel (joinCh , userJoin );
163
- break ;
164
- case "0" :
165
- return ;
166
- default :
167
- System .out .println ("표시되지 않은 번호를 눌렀습니다" );
168
- }
169
- }
170
- }
171
-
172
- private static void messageMenu (Scanner scanner , JCFMessageService messageService , JCFChannelService channelService , JCFUserService userService ) {
173
- while (true ) {
174
- System .out .println ("===== MESSAGE MENU =====" );
175
- System .out .println ("1. 메시지 생성" );
176
- System .out .println ("2. 메시지 단건 조회" );
177
- System .out .println ("3. 메시지 다건 조회" );
178
- System .out .println ("4. 메시지 수정" );
179
- System .out .println ("5. 메시지 삭제" );
180
- System .out .println ("0. 초기 화면으로" );
181
- System .out .println ("번호를 입력하세요" );
182
- String select = scanner .nextLine ();
183
-
184
- switch (select ) {
185
- case "1" :
186
- System .out .print ("보낼 메시지 내용" );
187
- String content = scanner .nextLine ();
188
- System .out .print ("보낸 사용자 식별키" );
189
- UUID senderId = UUID .fromString (scanner .nextLine ());
190
- System .out .print ("보낼 채널 식별키" );
191
- UUID channelId = UUID .fromString (scanner .nextLine ());
192
- Message message = messageService .createMessageCheck (content , senderId , channelId );
193
- System .out .println ("생성된 메시지 식별키 " + message .getId ());
194
- break ;
195
- case "2" :
196
- System .out .print ("조회할 메시지 식별키 입력" );
197
- UUID messageId = UUID .fromString (scanner .nextLine ());
198
- Message msg = messageService .getMessage (messageId );
199
- if (msg != null ) {
200
- System .out .println (msg );
201
- } else {
202
- System .out .println ("메시지를 찾을 수 없습니다." );
203
- }
204
- break ;
205
- case "3" :
206
- messageService .getAllMessages ().forEach (System .out ::println );
207
- break ;
208
- case "4" :
209
- System .out .print ("수정할 메시지 식별키 입력" );
210
- UUID msgId = UUID .fromString (scanner .nextLine ());
211
- System .out .print ("새 메시지 내용 입력" );
212
- String newMsg = scanner .nextLine ();
213
- messageService .updateMessage (msgId , newMsg );
214
- break ;
215
- case "5" :
216
- System .out .print ("삭제할 메시지 식별키 입력" );
217
- UUID delId = UUID .fromString (scanner .nextLine ());
218
- messageService .deleteMessage (delId );
219
- break ;
220
- case "0" :
221
- return ;
222
- default :
223
- System .out .println ("표시되지 않은 번호를 눌렀습니다" );
28
+ System .out .print ("번호를 입력하세요: " );
29
+
30
+ String mainChoice = scanner .nextLine ();
31
+
32
+ try {
33
+ switch (mainChoice ) {
34
+ case "1" :
35
+ UserMenu .manageUsers (scanner , userService );
36
+ break ;
37
+ case "2" :
38
+ ChannelMenu .manageChannels (scanner , channelService , userService );
39
+ break ;
40
+ case "3" :
41
+ MessageMenu .manageMessages (scanner , messageService , userService , channelService );
42
+ break ;
43
+ case "0" :
44
+ System .out .println ("종료합니다." );
45
+ return ;
46
+ default :
47
+ System .out .println ("올바른 번호를 선택하세요." );
48
+ }
49
+ } catch (Exception e ) {
50
+ System .out .println ("[오류] 메뉴 처리 중 문제가 발생했습니다: " + e .getMessage ());
224
51
}
225
52
}
226
53
}
227
- }
54
+ }
0 commit comments