|
12 | 12 | import com.sprint.mission.discodeit.domain.channel.Channel;
|
13 | 13 | import com.sprint.mission.discodeit.domain.channel.enums.ChannelType;
|
14 | 14 | import com.sprint.mission.discodeit.domain.channel.enums.ChannelVisibility;
|
| 15 | +import com.sprint.mission.discodeit.domain.channel.exception.AlreadyJoinUserException; |
15 | 16 | import com.sprint.mission.discodeit.domain.channel.exception.ChannelNotFoundException;
|
16 | 17 | import com.sprint.mission.discodeit.domain.readStatus.ReadStatus;
|
17 | 18 | import com.sprint.mission.discodeit.domain.user.User;
|
@@ -73,6 +74,7 @@ public void joinPublicChannel(UUID invitedUserId, InviteChannelRequestDto reques
|
73 | 74 | public void joinPrivateChannel(UUID invitedUserId, InviteChannelRequestDto requestDto) {
|
74 | 75 | User foundUser = userService.findOneByIdOrThrow(invitedUserId);
|
75 | 76 | Channel foundChannel = findOneByIdOrThrow(requestDto.channelId());
|
| 77 | + throwIsAlreadyJoinUser(foundUser, foundChannel); |
76 | 78 | foundChannel.join(foundUser);
|
77 | 79 | ReadStatus readStatus = new ReadStatus(foundUser, foundChannel);
|
78 | 80 | readStatusRepository.save(readStatus);
|
@@ -139,4 +141,10 @@ private FoundChannelResponseDto toFoundChannelResponseDto(Channel foundChannel)
|
139 | 141 | return FoundChannelResponseDto.ofPrivateChannel(foundChannel, lastMessageTime);
|
140 | 142 | }
|
141 | 143 | }
|
| 144 | + |
| 145 | + private void throwIsAlreadyJoinUser(User targetUser, Channel targetChannel) { |
| 146 | + if (channelRepository.isExistUser(targetUser, targetChannel)) { |
| 147 | + throw new AlreadyJoinUserException(ErrorCode.ALREADY_CHANNEL_JOIN_USER, targetUser.getNicknameValue()); |
| 148 | + } |
| 149 | + } |
142 | 150 | }
|
0 commit comments