|
1 | | -package com.sprint.mission.discodeit.jcf; |
2 | | - |
3 | | -import com.sprint.mission.discodeit.entity.Channel; |
4 | | -import com.sprint.mission.discodeit.entity.User; |
5 | | -import com.sprint.mission.discodeit.exception.DataNotFoundException; |
6 | | -import com.sprint.mission.discodeit.exception.IdNotFoundException; |
7 | | -import com.sprint.mission.discodeit.service.ChannelService; |
8 | | -import groovyjarjarasm.asm.tree.TryCatchBlockNode; |
9 | | - |
10 | | -import java.util.*; |
11 | | - |
12 | | -public class JCFChannelService implements ChannelService { |
13 | | - private final Map<UUID, Channel> data; |
14 | | - |
15 | | - public JCFChannelService(){ |
16 | | - this.data = new HashMap<>(); |
17 | | - } |
18 | | - |
19 | | - @Override |
20 | | - public Channel create(Channel channel) { |
21 | | - data.put(channel.getId(), channel); |
22 | | - System.out.println(channel.getName() + " 채널이 오픈되었습니다."); |
23 | | - return channel; |
24 | | - } |
25 | | - |
26 | | - @Override |
27 | | - public Channel readOne(UUID id) { |
28 | | - return data.get(id); |
29 | | - } |
30 | | - |
31 | | - @Override |
32 | | - public List<Channel> readAll() { |
33 | | - data.values().forEach(channel -> { |
34 | | - System.out.println(channel.getName()); |
35 | | - }); |
36 | | - |
37 | | - return new ArrayList<>(data.values()); |
38 | | - } |
39 | | - |
40 | | - @Override |
41 | | - public Channel update(UUID id, Channel updatedChannel) { |
42 | | - try{ |
43 | | - if(data.containsKey(id)){ |
44 | | - Channel existingChannel = data.get(id); |
45 | | - existingChannel.setName(updatedChannel.getName()); |
46 | | - existingChannel.setDescription(updatedChannel.getDescription()); |
47 | | - updatedChannel.update(); |
48 | | - return existingChannel; |
49 | | - } |
50 | | - }catch (DataNotFoundException e){ |
51 | | - throw new DataNotFoundException("채널을 찾을 수 없습니다." + e); |
52 | | - } |
53 | | - return null; |
54 | | - } |
55 | | - |
56 | | - @Override |
57 | | - public void channelOwnerChange(UUID id, User owner){ |
58 | | - try { |
59 | | - if(data.containsKey(id)){ |
60 | | - Channel existingChannel = data.get(id); |
61 | | - User existingOwnerName = existingChannel.getOwner(); |
62 | | - existingChannel.setOwner(owner); |
63 | | - existingChannel.update(); |
64 | | - System.out.println("채널 주인이 " + existingOwnerName.getUsername() + "님에서 " + owner.getUsername() + "님으로 변경되었습니다."); |
65 | | - } |
66 | | - }catch (DataNotFoundException e){ |
67 | | - throw new DataNotFoundException("채널을 찾을 수 없습니다." + e); |
68 | | - } |
69 | | - } |
70 | | - |
71 | | - @Override |
72 | | - public boolean delete(UUID id) { |
73 | | - try{ |
74 | | - String removename = data.get(id).getName(); |
75 | | - data.remove(id); |
76 | | - System.out.println(removename +" 삭제가 완료되었습니다."); |
77 | | - return true; |
78 | | - } catch (NullPointerException e){ |
79 | | - System.out.println("유효하지 않은 ID 입니다..\n" + e); |
80 | | - } |
81 | | - return false; |
82 | | - } |
83 | | - |
84 | | - @Override |
85 | | - public void channelMemberJoin(UUID id, User joinUser){ |
86 | | - try { |
87 | | - if (data.containsKey(id)) { |
88 | | - Channel joinChannel = data.get(id); |
89 | | - |
90 | | - List<User> members = new ArrayList<>(joinChannel.getMember()); |
91 | | - if (!members.contains(joinUser)) { |
92 | | - members.add(joinUser); |
93 | | - System.out.println(joinChannel.getName() + " 채널에 " + joinUser.getUsername() + "님이 등록되었습니다."); |
94 | | - } else { |
95 | | - System.out.println("User is already a member."); |
96 | | - } |
97 | | - joinChannel.setMember(members); |
98 | | - } |
99 | | - }catch (DataNotFoundException e){ |
100 | | - throw new DataNotFoundException("채널을 찾을 수 없습니다."); |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - @Override |
105 | | - public void channelMemberWithdrawal(UUID id, User withdrawalUser){ |
106 | | - |
107 | | - } |
108 | | - |
109 | | -} |
| 1 | +//package com.sprint.mission.discodeit.jcf; |
| 2 | +// |
| 3 | +//import com.sprint.mission.discodeit.entity.Channel; |
| 4 | +//import com.sprint.mission.discodeit.entity.User; |
| 5 | +//import com.sprint.mission.discodeit.exception.DataNotFoundException; |
| 6 | +//import com.sprint.mission.discodeit.exception.IdNotFoundException; |
| 7 | +//import com.sprint.mission.discodeit.service.ChannelService; |
| 8 | +//import groovyjarjarasm.asm.tree.TryCatchBlockNode; |
| 9 | +// |
| 10 | +//import java.util.*; |
| 11 | +// |
| 12 | +//public class JCFChannelService implements ChannelService { |
| 13 | +// private final Map<UUID, Channel> data; |
| 14 | +// |
| 15 | +// public JCFChannelService(){ |
| 16 | +// this.data = new HashMap<>(); |
| 17 | +// } |
| 18 | +// |
| 19 | +// @Override |
| 20 | +// public Channel create(Channel channel) { |
| 21 | +// data.put(channel.getId(), channel); |
| 22 | +// System.out.println(channel.getName() + " 채널이 오픈되었습니다."); |
| 23 | +// return channel; |
| 24 | +// } |
| 25 | +// |
| 26 | +// @Override |
| 27 | +// public Channel readOne(UUID id) { |
| 28 | +// return data.get(id); |
| 29 | +// } |
| 30 | +// |
| 31 | +// @Override |
| 32 | +// public List<Channel> readAll() { |
| 33 | +// data.values().forEach(channel -> { |
| 34 | +// System.out.println(channel.getName()); |
| 35 | +// }); |
| 36 | +// |
| 37 | +// return new ArrayList<>(data.values()); |
| 38 | +// } |
| 39 | +// |
| 40 | +// @Override |
| 41 | +// public Channel update(UUID id, Channel updatedChannel) { |
| 42 | +// try{ |
| 43 | +// if(data.containsKey(id)){ |
| 44 | +// Channel existingChannel = data.get(id); |
| 45 | +// existingChannel.setName(updatedChannel.getName()); |
| 46 | +// existingChannel.setDescription(updatedChannel.getDescription()); |
| 47 | +// updatedChannel.update(); |
| 48 | +// return existingChannel; |
| 49 | +// } |
| 50 | +// }catch (DataNotFoundException e){ |
| 51 | +// throw new DataNotFoundException("채널을 찾을 수 없습니다." + e); |
| 52 | +// } |
| 53 | +// return null; |
| 54 | +// } |
| 55 | +// |
| 56 | +// @Override |
| 57 | +// public void channelOwnerChange(UUID id, User owner){ |
| 58 | +// try { |
| 59 | +// if(data.containsKey(id)){ |
| 60 | +// Channel existingChannel = data.get(id); |
| 61 | +// User existingOwnerName = existingChannel.getOwner(); |
| 62 | +// existingChannel.setOwner(owner); |
| 63 | +// existingChannel.update(); |
| 64 | +// System.out.println("채널 주인이 " + existingOwnerName.getUsername() + "님에서 " + owner.getUsername() + "님으로 변경되었습니다."); |
| 65 | +// } |
| 66 | +// }catch (DataNotFoundException e){ |
| 67 | +// throw new DataNotFoundException("채널을 찾을 수 없습니다." + e); |
| 68 | +// } |
| 69 | +// } |
| 70 | +// |
| 71 | +// @Override |
| 72 | +// public boolean delete(UUID id) { |
| 73 | +// try{ |
| 74 | +// String removename = data.get(id).getName(); |
| 75 | +// data.remove(id); |
| 76 | +// System.out.println(removename +" 삭제가 완료되었습니다."); |
| 77 | +// return true; |
| 78 | +// } catch (NullPointerException e){ |
| 79 | +// System.out.println("유효하지 않은 ID 입니다..\n" + e); |
| 80 | +// } |
| 81 | +// return false; |
| 82 | +// } |
| 83 | +// |
| 84 | +// @Override |
| 85 | +// public void channelMemberJoin(UUID id, User joinUser){ |
| 86 | +// try { |
| 87 | +// if (data.containsKey(id)) { |
| 88 | +// Channel joinChannel = data.get(id); |
| 89 | +// |
| 90 | +// List<User> members = new ArrayList<>(joinChannel.getMember()); |
| 91 | +// if (!members.contains(joinUser)) { |
| 92 | +// members.add(joinUser); |
| 93 | +// System.out.println(joinChannel.getName() + " 채널에 " + joinUser.getUsername() + "님이 등록되었습니다."); |
| 94 | +// } else { |
| 95 | +// System.out.println("User is already a member."); |
| 96 | +// } |
| 97 | +// joinChannel.setMember(members); |
| 98 | +// } |
| 99 | +// }catch (DataNotFoundException e){ |
| 100 | +// throw new DataNotFoundException("채널을 찾을 수 없습니다."); |
| 101 | +// } |
| 102 | +// } |
| 103 | +// |
| 104 | +// @Override |
| 105 | +// public void channelMemberWithdrawal(UUID id, User withdrawalUser){ |
| 106 | +// |
| 107 | +// } |
| 108 | +// |
| 109 | +//} |
0 commit comments