Skip to content

Commit

Permalink
refactor: 탈퇴한 회원의 리뷰일 경우 처리 로직 추가 #117
Browse files Browse the repository at this point in the history
탈퇴한 회원일 경우
- reviewerId
- reviewerNickname
- reviewerProfileImageUrl
- isFollowing
responseDto 필드값 null 처리
  • Loading branch information
chaewss committed Apr 21, 2024
1 parent 9afe15f commit ff7c42a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class ReadProductReviewQueryDto {

private final String reviewerProfileImageUrl;

private final Boolean reviewerIsDeleted;

private final boolean isFollowing;

private final String content;
Expand All @@ -31,12 +33,13 @@ public class ReadProductReviewQueryDto {

@QueryProjection
public ReadProductReviewQueryDto(long reviewerId, long reviewId, String reviewerNickname,
String reviewerProfileImageUrl, UserFollow userFollow, String content, int rating,
ReviewLike reviewLike, long likeCount, LocalDateTime createdAt) {
String reviewerProfileImageUrl, boolean reviewerIsDeleted, UserFollow userFollow,
String content, int rating, ReviewLike reviewLike, long likeCount, LocalDateTime createdAt) {
this.reviewerId = reviewerId;
this.reviewId = reviewId;
this.reviewerNickname = reviewerNickname;
this.reviewerProfileImageUrl = reviewerProfileImageUrl;
this.reviewerIsDeleted = reviewerIsDeleted;
this.isFollowing = userFollow != null;
this.content = content;
this.rating = rating;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,21 @@ private ReadProductReviewResponseDto(Long reviewId, Long reviewerId, String revi
this.createdAt = createdAt;
}

public static ReadProductReviewResponseDto of(ReadProductReviewQueryDto queryDto, User loginUser,
List<String> reviewImageUrls, List<String> tags) {
public static ReadProductReviewResponseDto of(ReadProductReviewQueryDto queryDto,
User loginUser, List<String> reviewImageUrls, List<String> tags) {
boolean isReviewerDeleted = queryDto.getReviewerIsDeleted();
return ReadProductReviewResponseDto.builder()
.reviewContent(queryDto.getContent())
.reviewId(queryDto.getReviewId())
.reviewerId(queryDto.getReviewerId())
.reviewerId(isReviewerDeleted ? null : queryDto.getReviewerId())
.reviewerNickname(isReviewerDeleted ? null : queryDto.getReviewerNickname())
.reviewerProfileImageUrl(
isReviewerDeleted ? null : queryDto.getReviewerProfileImageUrl())
.isFollowingUser(isReviewerDeleted ? null : queryDto.isFollowing())
.reviewRating(queryDto.getRating())
.isReviewLiked(queryDto.isReviewLiked())
.reviewLikeCount(queryDto.getLikeCount())
.isFollowingUser(queryDto.isFollowing())
.isMe(loginUser != null && loginUser.getId() == queryDto.getReviewerId())
.reviewerNickname(queryDto.getReviewerNickname())
.reviewerProfileImageUrl(queryDto.getReviewerProfileImageUrl())
.reviewImages(reviewImageUrls)
.createdAt(queryDto.getCreatedAt())
.tags(tags)
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/cvsgo/dto/review/ReadReviewQueryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class ReadReviewQueryDto {

private final String reviewerProfileImageUrl;

private final Boolean reviewerIsDeleted;

private final boolean isFollowing;

private final Long likeCount;
Expand All @@ -43,9 +45,9 @@ public class ReadReviewQueryDto {
@QueryProjection
public ReadReviewQueryDto(Long reviewId, Long productId, String productName,
String manufacturerName, String productImageUrl, Long reviewerId, String reviewerNickname,
String reviewerProfileImageUrl, UserFollow userFollow, Long likeCount, Integer rating,
String reviewContent, LocalDateTime createdAt, ReviewLike reviewLike,
ProductBookmark productBookmark) {
String reviewerProfileImageUrl, boolean reviewerIsDeleted, UserFollow userFollow,
Long likeCount, Integer rating, String reviewContent, LocalDateTime createdAt,
ReviewLike reviewLike, ProductBookmark productBookmark) {
this.reviewId = reviewId;
this.productId = productId;
this.productName = productName;
Expand All @@ -54,6 +56,7 @@ public ReadReviewQueryDto(Long reviewId, Long productId, String productName,
this.reviewerId = reviewerId;
this.reviewerNickname = reviewerNickname;
this.reviewerProfileImageUrl = reviewerProfileImageUrl;
this.reviewerIsDeleted = reviewerIsDeleted;
this.isFollowing = userFollow != null;
this.likeCount = likeCount;
this.rating = rating;
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/cvsgo/dto/review/ReviewDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ReviewDto {
@Builder
public ReviewDto(Long productId, String productName, String productManufacturer,
String productImageUrl, Long reviewId, Long reviewerId, String reviewerNickname,
String reviewerProfileImageUrl, boolean isFollowing, List<String> reviewerTags,
String reviewerProfileImageUrl, Boolean isFollowing, List<String> reviewerTags,
Long reviewLikeCount, Integer reviewRating, String reviewContent, LocalDateTime createdAt,
Boolean isReviewLiked, Boolean isProductBookmarked, List<String> reviewImageUrls) {
this.productId = productId;
Expand All @@ -71,17 +71,19 @@ public ReviewDto(Long productId, String productName, String productManufacturer,

public static ReviewDto of(ReadReviewQueryDto readReviewQueryDto,
List<String> reviewImageUrls, List<String> tags) {
boolean isReviewerDeleted = readReviewQueryDto.getReviewerIsDeleted();
return ReviewDto.builder()
.productName(readReviewQueryDto.getProductName())
.productId(readReviewQueryDto.getProductId())
.reviewContent(readReviewQueryDto.getReviewContent())
.productImageUrl(readReviewQueryDto.getProductImageUrl())
.isFollowing(readReviewQueryDto.isFollowing())
.productManufacturer(readReviewQueryDto.getManufacturerName())
.reviewId(readReviewQueryDto.getReviewId())
.reviewerId(readReviewQueryDto.getReviewerId())
.reviewerNickname(readReviewQueryDto.getReviewerNickname())
.reviewerProfileImageUrl(readReviewQueryDto.getReviewerProfileImageUrl())
.reviewerId(isReviewerDeleted ? null : readReviewQueryDto.getReviewerId())
.reviewerNickname(isReviewerDeleted ? null : readReviewQueryDto.getReviewerNickname())
.reviewerProfileImageUrl(
isReviewerDeleted ? null : readReviewQueryDto.getReviewerProfileImageUrl())
.isFollowing(isReviewerDeleted ? null : readReviewQueryDto.isFollowing())
.reviewRating(readReviewQueryDto.getRating())
.reviewLikeCount(readReviewQueryDto.getLikeCount())
.createdAt(readReviewQueryDto.getCreatedAt())
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/cvsgo/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ public class User extends BaseTimeEntity {
private List<UserTag> userTags = new ArrayList<>();

@Builder
public User(Long id, String userId, String password, String nickname, Role role) {
public User(Long id, String userId, String password, String nickname, Role role, Boolean isDeleted) {
this.id = id;
this.userId = userId;
this.password = password;
this.nickname = nickname;
this.role = role;
this.isDeleted = isDeleted;
}

public static User create(String userId, String password, String nickname, List<Tag> tags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public List<ReadReviewQueryDto> findAllByFilter(User loginUser,
review.user.id,
review.user.nickname,
review.user.profileImageUrl,
review.user.isDeleted,
userFollow,
review.likeCount,
review.rating,
Expand Down Expand Up @@ -85,6 +86,7 @@ public List<ReadProductReviewQueryDto> findAllByProductIdAndFilter(User loginUse
review.id,
user.nickname,
user.profileImageUrl,
user.isDeleted,
userFollow,
review.content,
review.rating,
Expand Down
17 changes: 9 additions & 8 deletions src/test/java/com/cvsgo/controller/ReviewControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ void respond_200_when_success_to_read_reviews() throws Exception {
fieldWithPath("data.reviews[].productManufacturer").type(JsonFieldType.STRING).description("상품 제조사"),
fieldWithPath("data.reviews[].productImageUrl").type(JsonFieldType.STRING).description("상품 이미지 URL"),
fieldWithPath("data.reviews[].reviewId").type(JsonFieldType.NUMBER).description("리뷰 ID"),
fieldWithPath("data.reviews[].reviewerId").type(JsonFieldType.NUMBER).description("리뷰 작성자 ID"),
fieldWithPath("data.reviews[].reviewerNickname").type(JsonFieldType.STRING).description("리뷰 작성자 닉네임"),
fieldWithPath("data.reviews[].reviewerProfileImageUrl").type(JsonFieldType.STRING).description("리뷰 작성자 프로필 이미지 URL"),
fieldWithPath("data.reviews[].reviewerId").type(JsonFieldType.NUMBER).description("리뷰 작성자 ID").optional(),
fieldWithPath("data.reviews[].reviewerNickname").type(JsonFieldType.STRING).description("리뷰 작성자 닉네임").optional(),
fieldWithPath("data.reviews[].reviewerProfileImageUrl").type(JsonFieldType.STRING).description("리뷰 작성자 프로필 이미지 URL").optional(),
fieldWithPath("data.content[].isFollowing").type(JsonFieldType.BOOLEAN).description("사용자가 리뷰 작성자를 팔로우하는지 여부").optional(),
fieldWithPath("data.reviews[].reviewerTags").type(JsonFieldType.ARRAY).description("리뷰 작성자의 태그 목록"),
fieldWithPath("data.reviews[].reviewLikeCount").type(JsonFieldType.NUMBER).description("리뷰 좋아요 개수"),
fieldWithPath("data.reviews[].reviewRating").type(JsonFieldType.NUMBER).description("리뷰 별점"),
Expand All @@ -210,7 +211,7 @@ void respond_200_when_success_to_read_product_reviews() throws Exception {
Review review = Review.builder().id(1L).rating(4).content("맛있어요").user(reviewer)
.imageUrls(List.of()).build();
ReadProductReviewQueryDto readProductReviewQueryDto = new ReadProductReviewQueryDto(reviewer.getId(),
review.getId(), reviewer.getNickname(), reviewer.getProfileImageUrl(), null,
review.getId(), reviewer.getNickname(), reviewer.getProfileImageUrl(), true, null,
review.getContent(), review.getRating(), null, review.getLikeCount(),
LocalDateTime.now());
ReadProductReviewResponseDto responseDto = ReadProductReviewResponseDto.of(readProductReviewQueryDto, reviewer,
Expand All @@ -233,15 +234,15 @@ void respond_200_when_success_to_read_product_reviews() throws Exception {
),
relaxedResponseFields(
fieldWithPath("data.content[].reviewId").type(JsonFieldType.NUMBER).description("리뷰 ID"),
fieldWithPath("data.content[].reviewerId").type(JsonFieldType.NUMBER).description("리뷰 작성자 ID"),
fieldWithPath("data.content[].reviewerNickname").type(JsonFieldType.STRING).description("리뷰 작성자 닉네임"),
fieldWithPath("data.content[].reviewerProfileImageUrl").type(JsonFieldType.STRING).description("리뷰 작성자 프로필 이미지 URL").optional(),
fieldWithPath("data.content[].reviewerId").type(JsonFieldType.NUMBER).description("리뷰 작성자 ID").optional(),
fieldWithPath("data.content[].reviewerNickname").type(JsonFieldType.STRING).description("리뷰 작성자 닉네임").optional(),
fieldWithPath("data.content[].reviewerProfileImageUrl").type(JsonFieldType.STRING).description("리뷰 작성자 프로필 이미지 URL").optional().optional(),
fieldWithPath("data.content[].isFollowingUser").type(JsonFieldType.BOOLEAN).description("사용자가 리뷰 작성자를 팔로우하는지 여부").optional(),
fieldWithPath("data.content[].reviewerTags").type(JsonFieldType.ARRAY).description("리뷰 작성자의 태그 목록"),
fieldWithPath("data.content[].reviewLikeCount").type(JsonFieldType.NUMBER).description("리뷰 좋아요 개수"),
fieldWithPath("data.content[].reviewRating").type(JsonFieldType.NUMBER).description("리뷰 별점"),
fieldWithPath("data.content[].reviewContent").type(JsonFieldType.STRING).description("리뷰 내용"),
fieldWithPath("data.content[].isReviewLiked").type(JsonFieldType.BOOLEAN).description("사용자의 리뷰 좋아요 여부"),
fieldWithPath("data.content[].isFollowingUser").type(JsonFieldType.BOOLEAN).description("사용자가 리뷰 작성자를 팔로우하는지 여부"),
fieldWithPath("data.content[].isMe").type(JsonFieldType.BOOLEAN).description("로그인한 사용자가 리뷰 작성자인지 여부"),
fieldWithPath("data.content[].reviewImages").type(JsonFieldType.ARRAY).description("리뷰 이미지 URL 목록"),
fieldWithPath("data.content[].createdAt").type(JsonFieldType.STRING).description("리뷰 생성 시간").optional()
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/com/cvsgo/service/ReviewServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void succeed_to_read_review() {
@DisplayName("특정 상품의 리뷰를 정상적으로 조회한다")
void succeed_to_read_product_review() {
ReadProductReviewQueryDto queryDto1 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewRequestDto requestDto = new ReadProductReviewRequestDto(List.of(1L, 2L, 3L),
List.of(4, 5), ReviewSortBy.LATEST);
Expand Down Expand Up @@ -173,22 +173,22 @@ void succeed_to_read_product_review() {
@DisplayName("준회원인 사용자가 특정 상품의 리뷰 0페이지를 조회하면 5개만 조회된다")
void should_get_only_five_reviews_when_associate_user_read_first_page_of_product_reviews() {
ReadProductReviewQueryDto queryDto1 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto2 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto3 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto4 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto5 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto6 = new ReadProductReviewQueryDto(user1.getId(), review.getId(),
user1.getNickname(), user1.getProfileImageUrl(), userFollow, review.getContent(),
user1.getNickname(), user1.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewRequestDto requestDto = new ReadProductReviewRequestDto(List.of(1L, 2L, 3L),
List.of(4, 5), ReviewSortBy.LATEST);
Expand Down Expand Up @@ -225,22 +225,22 @@ void should_get_only_five_reviews_when_associate_user_read_first_page_of_product
@DisplayName("정회원인 사용자가 특정 상품의 리뷰 0페이지를 조회하면 정상적으로 조회된다")
void should_success_to_read_product_reviews_when_regular_user_read_first_page_of_product_reviews() {
ReadProductReviewQueryDto queryDto1 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto2 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto3 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto4 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto5 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewQueryDto queryDto6 = new ReadProductReviewQueryDto(user2.getId(), review.getId(),
user2.getNickname(), user2.getProfileImageUrl(), userFollow, review.getContent(),
user2.getNickname(), user2.getProfileImageUrl(), false, userFollow, review.getContent(),
review.getRating(), null, review.getLikeCount(), LocalDateTime.now());
ReadProductReviewRequestDto requestDto = new ReadProductReviewRequestDto(List.of(1L, 2L, 3L),
List.of(4, 5), ReviewSortBy.LATEST);
Expand Down Expand Up @@ -497,7 +497,7 @@ void should_throw_NotFoundException_when_delete_review_but_review_does_not_exist

ReadReviewQueryDto readReviewQueryDto = new ReadReviewQueryDto(1L, 2L,
"불닭볶음면큰컵", "삼양", "https://어쩌구저쩌구/products/불닭볶음면.png",
user1.getId(), user1.getNickname(), user1.getProfileImageUrl(), null, 3L,
user1.getId(), user1.getNickname(), user1.getProfileImageUrl(), false, null, 3L,
4, "맛있어요", LocalDateTime.now(), null, null);

Tag tag = Tag.builder()
Expand Down

0 comments on commit ff7c42a

Please sign in to comment.