-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from jisung-in/feature/36-talkroom-delete-api
[Feature] TalkRoom 삭제 API 구현
- Loading branch information
Showing
7 changed files
with
157 additions
and
17 deletions.
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) | ||
|