Skip to content
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

[BE] fix: 리뷰 좋아요 시 NPE 발생 수정 #274

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ReviewFavorite {
@JoinColumn(name = "review_id")
private Review review;

private Boolean checked;
private Boolean favorite;

protected ReviewFavorite() {
}
Expand All @@ -39,12 +39,13 @@ public static ReviewFavorite createReviewFavoriteByMemberAndReview(final Member
final ReviewFavorite reviewFavorite = new ReviewFavorite(member, review);
reviewFavorite.review.getReviewFavorites().add(reviewFavorite);
reviewFavorite.member.getReviewFavorites().add(reviewFavorite);
reviewFavorite.favorite = favorite;
return reviewFavorite;
}

public void updateChecked(final Boolean checked) {
this.checked = checked;
if (checked) {
public void updateChecked(final Boolean favorite) {
this.favorite = favorite;
if (favorite) {
this.review.addFavoriteCount();
return;
}
Expand All @@ -64,7 +65,7 @@ public Review getReview() {
return review;
}

public Boolean getChecked() {
return checked;
public Boolean getFavorite() {
return favorite;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public void create(final Long productId, final Long memberId, final MultipartFil
if (Objects.isNull(image)) {
savedReview = reviewRepository.save(
new Review(findMember, findProduct, reviewRequest.getRating(), reviewRequest.getContent(),
reviewRequest.getReBuy()));
reviewRequest.getRebuy()));
} else {
savedReview = reviewRepository.save(
new Review(findMember, findProduct, image.getOriginalFilename(), reviewRequest.getRating(),
reviewRequest.getContent(), reviewRequest.getReBuy()));
reviewRequest.getContent(), reviewRequest.getRebuy()));
imageService.upload(image);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ public class ReviewCreateRequest {
private final Long rating;
private final List<Long> tagIds;
private final String content;
private final Boolean reBuy;
private final Boolean rebuy;

public ReviewCreateRequest(final Long rating, final List<Long> tagIds, final String content, final Boolean reBuy) {
public ReviewCreateRequest(final Long rating, final List<Long> tagIds, final String content, final Boolean rebuy) {
this.rating = rating;
this.tagIds = tagIds;
this.content = content;
this.reBuy = reBuy;
this.rebuy = rebuy;
}

public Long getRating() {
Expand All @@ -24,8 +24,8 @@ public String getContent() {
return content;
}

public Boolean getReBuy() {
return reBuy;
public Boolean getRebuy() {
return rebuy;
}

public List<Long> getTagIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static boolean findReviewFavoriteChecked(final Review review) {
.filter(reviewFavorite -> reviewFavorite.getReview().equals(review))
.filter(reviewFavorite -> reviewFavorite.getMember().equals(review.getMember()))
.findFirst()
.map(ReviewFavorite::getChecked)
.map(ReviewFavorite::getFavorite)
.orElse(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ReviewAcceptanceTest extends AcceptanceTest {
// then
STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT);
리뷰_좋아요_결과를_검증한다(result, savedMemberId, savedReviewId);
assertThat(result.getChecked()).isTrue();
assertThat(result.getFavorite()).isTrue();
}

@Test
Expand All @@ -101,7 +101,7 @@ class ReviewAcceptanceTest extends AcceptanceTest {
// then
STATUS_CODE를_검증한다(response, 정상_처리_NO_CONTENT);
리뷰_좋아요_결과를_검증한다(result, savedMemberId, savedReview.getId());
assertThat(result.getChecked()).isFalse();
assertThat(result.getFavorite()).isFalse();
}

private void 리뷰_좋아요_결과를_검증한다(final ReviewFavorite result, final Long memberId, final Long reviewId) {
Expand Down
Loading