-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] TalkRoom 삭제 API 구현 #37
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/java/com/jisungin/domain/comment/repository/CommentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package com.jisungin.domain.comment.repository; | ||
|
||
import com.jisungin.domain.comment.Comment; | ||
import com.jisungin.domain.talkroom.TalkRoom; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
|
||
Optional<Comment> findByTalkRoom(TalkRoom talkRoom); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -453,11 +453,7 @@ void findOneTalkRoom() { | |
|
||
createTalkRoomRole(talkRoom); | ||
|
||
Comment comment = Comment.builder() | ||
.talkRoom(talkRoom) | ||
.user(user) | ||
.content("의견 남기기") | ||
.build(); | ||
Comment comment = createComment(talkRoom, user); | ||
|
||
commentRepository.save(comment); | ||
// when | ||
|
@@ -470,17 +466,6 @@ void findOneTalkRoom() { | |
assertThat("[email protected]").isEqualTo(findOneTalkRoomResponse.getComments().get(0).getUserName()); | ||
} | ||
|
||
private void createTalkRoomRole(TalkRoom talkRoom) { | ||
List<String> request = new ArrayList<>(); | ||
request.add("읽는 중"); | ||
request.add("읽음"); | ||
|
||
List<ReadingStatus> readingStatus = ReadingStatus.createReadingStatus(request); | ||
|
||
readingStatus.stream().map(status -> TalkRoomRole.roleCreate(talkRoom, status)) | ||
.forEach(talkRoomRoleRepository::save); | ||
} | ||
|
||
@Test | ||
@DisplayName("토크방을 단건 조회 했을 때 의견이 담기지 않았아도 조회는 정상적으로 되어야 한다.") | ||
void findOneTalkRoomWithCommentNull() { | ||
|
@@ -539,6 +524,111 @@ void findOneTalkRoomWithFindAllComment() { | |
assertThat("의견 19").isEqualTo(findOneTalkRoomResponse.getComments().get(19).getContent()); | ||
} | ||
|
||
@Test | ||
@DisplayName("토크방을 생성한 유저가 토크방을 삭제한다.") | ||
void deleteTalkRoom() { | ||
// given | ||
User user = createUser(); | ||
userRepository.save(user); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
TalkRoom talkRoom = createTalkRoom(book, user); | ||
talkRoomRepository.save(talkRoom); | ||
|
||
createTalkRoomRole(talkRoom); | ||
|
||
Comment comment = createComment(talkRoom, user); | ||
|
||
commentRepository.save(comment); | ||
|
||
// when | ||
talkRoomService.deleteTalkRoom(talkRoom.getId(), user.getId()); | ||
|
||
// then | ||
assertThat(0).isEqualTo(talkRoomRepository.findAll().size()); | ||
assertThat(0).isEqualTo(commentRepository.findAll().size()); | ||
} | ||
|
||
@Test | ||
@DisplayName("토크방을 생성하지 않은 유저(UserB)가 다른 유저(UserA)가 생성한 토크방을 삭제할 수 없다.") | ||
void deleteTalkRoomWithUserB() { | ||
// given | ||
User userA = createUser(); | ||
userRepository.save(userA); | ||
|
||
User userB = User.builder() | ||
.name("[email protected]") | ||
.profileImage("image") | ||
.oauthId( | ||
OauthId.builder() | ||
.oauthId("oauthId2") | ||
.oauthType(OauthType.KAKAO) | ||
.build() | ||
) | ||
.build(); | ||
userRepository.save(userB); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
TalkRoom talkRoom = createTalkRoom(book, userA); | ||
talkRoomRepository.save(talkRoom); | ||
|
||
createTalkRoomRole(talkRoom); | ||
|
||
Comment comment = createComment(talkRoom, userA); | ||
|
||
commentRepository.save(comment); | ||
|
||
// when // then | ||
assertThatThrownBy(() -> talkRoomService.deleteTalkRoom(talkRoom.getId(), userB.getId())) | ||
.isInstanceOf(BusinessException.class) | ||
.hasMessage("권한이 없는 사용자입니다."); | ||
} | ||
|
||
@Test | ||
@DisplayName("토크방을 삭제할 때 의견이 없어도 정상적으로 삭제가 된다.") | ||
void deleteTalkRoomWithComment() { | ||
// given | ||
User user = createUser(); | ||
userRepository.save(user); | ||
|
||
Book book = createBook(); | ||
bookRepository.save(book); | ||
|
||
TalkRoom talkRoom = createTalkRoom(book, user); | ||
talkRoomRepository.save(talkRoom); | ||
|
||
createTalkRoomRole(talkRoom); | ||
|
||
// when | ||
talkRoomService.deleteTalkRoom(talkRoom.getId(), user.getId()); | ||
|
||
// then | ||
assertThat(0).isEqualTo(talkRoomRepository.findAll().size()); | ||
} | ||
|
||
private static Comment createComment(TalkRoom talkRoom, User user) { | ||
return Comment.builder() | ||
.talkRoom(talkRoom) | ||
.user(user) | ||
.content("의견 남기기") | ||
.build(); | ||
} | ||
|
||
private void createTalkRoomRole(TalkRoom talkRoom) { | ||
List<String> request = new ArrayList<>(); | ||
request.add("읽는 중"); | ||
request.add("읽음"); | ||
|
||
List<ReadingStatus> readingStatus = ReadingStatus.createReadingStatus(request); | ||
|
||
readingStatus.stream().map(status -> TalkRoomRole.roleCreate(talkRoom, status)) | ||
.forEach(talkRoomRoleRepository::save); | ||
} | ||
|
||
private static TalkRoom createTalkRoom(Book book, User user) { | ||
return TalkRoom.builder() | ||
.book(book) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
확인 했습니다!!