-
Notifications
You must be signed in to change notification settings - Fork 7
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
refactor(user): 좋아요 취소 로직 변경 및 user cascade 옵션 변경 #697
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,16 +49,16 @@ public class User extends BaseEntity { | |
|
||
private String bio = ""; | ||
|
||
@OneToMany(mappedBy = "author", cascade = CascadeType.ALL) | ||
@OneToMany(mappedBy = "author", cascade = CascadeType.REMOVE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ALL을 쓰는건 생각과 다르게 동작할 여지가 있는 것 같아요! |
||
private List<Feed> feeds = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL) | ||
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) | ||
private List<Like> likes = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "author", cascade = CascadeType.ALL, orphanRemoval = true) | ||
@OneToMany(mappedBy = "author", cascade = CascadeType.REMOVE) | ||
private List<Comment> comments = new ArrayList<>(); | ||
|
||
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE, orphanRemoval = true) | ||
@OneToMany(mappedBy = "user", cascade = CascadeType.REMOVE) | ||
private List<CommentLike> commentLikes = new ArrayList<>(); | ||
|
||
public User(String socialId, SocialType socialType, String nickName, String imageUrl) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ void addCommentLike() { | |
em.clear(); | ||
|
||
// then | ||
찰리가_쓴_피드에_찰리가_쓴_댓글 = commentRepository.getById(찰리가_쓴_피드에_찰리가_쓴_댓글.getId()); | ||
assertThat(찰리가_쓴_피드에_찰리가_쓴_댓글.getLikes()).hasSize(1); | ||
} | ||
Comment on lines
33
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전에는 db에 반영된 |
||
|
||
|
@@ -46,6 +47,7 @@ void addCommentLikeTwice() { | |
em.clear(); | ||
|
||
// when then | ||
찰리 = userRepository.getById(찰리.getId()); | ||
assertThatThrownBy(() -> commentLikeService.addCommentLike(찰리가_쓴_피드에_찰리가_쓴_댓글.getId(), 찰리)) | ||
.isInstanceOf(BadRequestException.class); | ||
} | ||
|
@@ -76,7 +78,6 @@ void deleteCommentLikeNotLiked() { | |
commentLikeService.addCommentLike(찰리가_쓴_피드에_찰리가_쓴_댓글.getId(), 찰리); | ||
em.flush(); | ||
em.clear(); | ||
assertThat(찰리가_쓴_피드에_찰리가_쓴_댓글.getLikes()).hasSize(1); | ||
|
||
// when | ||
Comment findComment1 = commentService.findEntityById(찰리가_쓴_피드에_찰리가_쓴_댓글.getId()); | ||
|
@@ -102,6 +103,7 @@ void addReplyLike() { | |
em.clear(); | ||
|
||
// then | ||
찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글 = commentRepository.getById(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getId()); | ||
assertThat(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getLikes()).hasSize(1); | ||
} | ||
|
||
|
@@ -115,6 +117,7 @@ void addReplyLikeTwice() { | |
em.clear(); | ||
|
||
// when then | ||
찰리 = userRepository.getById(찰리.getId()); | ||
assertThatThrownBy(() -> commentLikeService.addCommentLike(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getId(), 찰리)) | ||
.isInstanceOf(BadRequestException.class); | ||
} | ||
|
@@ -145,7 +148,6 @@ void deleteReplyLikeNotLiked() { | |
commentLikeService.addCommentLike(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getId(), 찰리); | ||
em.flush(); | ||
em.clear(); | ||
assertThat(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getLikes()).hasSize(1); | ||
|
||
// when | ||
Comment findComment1 = commentService.findEntityById(찰리가_쓴_피드에_찰리가_쓴_댓글에_포모가_쓴_대댓글.getId()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package com.wooteco.nolto.feed.application; | ||
|
||
import com.wooteco.nolto.admin.ui.dto.CommentsByFeedResponse; | ||
import com.wooteco.nolto.exception.ErrorType; | ||
import com.wooteco.nolto.exception.NotFoundException; | ||
import com.wooteco.nolto.exception.UnauthorizedException; | ||
import com.wooteco.nolto.feed.domain.Comment; | ||
import com.wooteco.nolto.feed.domain.Feed; | ||
import com.wooteco.nolto.feed.domain.repository.CommentRepository; | ||
import com.wooteco.nolto.feed.domain.repository.FeedRepository; | ||
import com.wooteco.nolto.feed.ui.dto.*; | ||
import com.wooteco.nolto.feed.ui.dto.FeedCardPaginationResponse; | ||
import com.wooteco.nolto.feed.ui.dto.FeedCardResponse; | ||
import com.wooteco.nolto.feed.ui.dto.FeedRequest; | ||
import com.wooteco.nolto.feed.ui.dto.FeedResponse; | ||
import com.wooteco.nolto.image.application.ImageService; | ||
import com.wooteco.nolto.tech.domain.Tech; | ||
import com.wooteco.nolto.tech.domain.TechRepository; | ||
|
@@ -27,10 +26,12 @@ | |
|
||
import javax.persistence.EntityManager; | ||
import javax.transaction.Transactional; | ||
import java.util.*; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.wooteco.nolto.FeedFixture.진행중_단계의_피드_생성; | ||
import static com.wooteco.nolto.TechFixture.*; | ||
import static com.wooteco.nolto.UserFixture.조엘_생성; | ||
import static com.wooteco.nolto.UserFixture.찰리_생성; | ||
|
@@ -280,6 +281,7 @@ void checkLikeWhenFindFeed() { | |
likeService.addLike(조엘, feedId1); | ||
em.flush(); | ||
em.clear(); | ||
조엘 = userRepository.getById(조엘.getId()); | ||
|
||
// when | ||
FeedResponse feedResponse = feedService.viewFeed(조엘, feedId1, true); | ||
|
@@ -295,6 +297,7 @@ void checkNotLikeWhenFindFeed() { | |
Long feedId1 = feedService.create(찰리, EMPTY_TECH_FEED_REQUEST); | ||
em.flush(); | ||
em.clear(); | ||
조엘 = userRepository.getById(조엘.getId()); | ||
|
||
// when | ||
FeedResponse feedResponse = feedService.viewFeed(조엘, feedId1, true); | ||
|
@@ -316,6 +319,7 @@ void cancelLike() { | |
likeService.deleteLike(조엘, feedId1); | ||
em.flush(); | ||
em.clear(); | ||
조엘 = userRepository.getById(조엘.getId()); | ||
FeedResponse feedResponse = feedService.viewFeed(조엘, feedId1, true); | ||
Comment on lines
321
to
323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 viewFeed 로직 안에서 user.isLiked(feed);로 좋아요 여부를 반환하는데, |
||
|
||
// then | ||
|
@@ -332,12 +336,15 @@ void cancelLikeWhenDeleteUser() { | |
em.clear(); | ||
|
||
// when | ||
조엘 = userRepository.getById(조엘.getId()); | ||
userRepository.delete(조엘); | ||
em.flush(); | ||
em.clear(); | ||
Feed findFeed = feedService.findEntityById(feedId1); | ||
|
||
// then | ||
조엘 = userRepository.getById(조엘.getId()); | ||
|
||
assertThat(findFeed.findLikeBy(조엘)).isEmpty(); | ||
} | ||
|
||
|
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.
CascadeType.REMOVE만 가져가고 orphanRemoval 없애주는 거 좋네요!