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

refactor: 마이페이지에 작성한 리뷰 정보 조회 변경 #59

Merged
merged 2 commits into from
May 24, 2024
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
44 changes: 30 additions & 14 deletions src/main/java/com/funeat/member/dto/MemberReviewDto.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
package com.funeat.member.dto;

import com.funeat.review.domain.Review;
import com.funeat.tag.domain.Tag;
import com.funeat.tag.dto.TagDto;

import java.time.LocalDateTime;
import java.util.List;

public class MemberReviewDto {

private final Long reviewId;
private final Long productId;
private final String categoryType;
private final String productName;
private final String content;
private final Long rating;
private final Long favoriteCount;
private final List<TagDto> tags;
private final String image;
private final LocalDateTime createdAt;

private MemberReviewDto(final Long reviewId, final Long productId, final String categoryType,
final String productName, final String content,
final Long rating, final Long favoriteCount) {
private MemberReviewDto(final Long reviewId, final Long productId, final String productName,
final String content, final Long rating, final List<TagDto> tags, final String image,
final LocalDateTime createdAt) {
this.reviewId = reviewId;
this.productId = productId;
this.categoryType = categoryType;
this.productName = productName;
this.content = content;
this.rating = rating;
this.favoriteCount = favoriteCount;
this.tags = tags;
this.image = image;
this.createdAt = createdAt;
}

public static MemberReviewDto toDto(final Review review) {
public static MemberReviewDto toDto(final Review review, final List<Tag> tags) {
final List<TagDto> tagDtos = tags.stream()
.map(TagDto::toDto)
.toList();

return new MemberReviewDto(
review.getId(),
review.getProduct().getId(),
review.getProduct().getCategory().getType().getName(),
review.getProduct().getName(),
review.getContent(),
review.getRating(),
review.getFavoriteCount()
tagDtos,
review.getImage(),
review.getCreatedAt()
);
}

Expand All @@ -56,11 +68,15 @@ public Long getRating() {
return rating;
}

public Long getFavoriteCount() {
return favoriteCount;
public List<TagDto> getTags() {
return tags;
}

public String getImage() {
return image;
}

public String getCategoryType() {
return categoryType;
public LocalDateTime getCreatedAt() {
return createdAt;
}
}
10 changes: 8 additions & 2 deletions src/main/java/com/funeat/review/application/ReviewService.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,18 @@ public MemberReviewsResponse findReviewByMember(final Long memberId, final Pagea
final PageDto pageDto = PageDto.toDto(sortedReviewPages);

final List<MemberReviewDto> dtos = sortedReviewPages.stream()
.map(MemberReviewDto::toDto)
.collect(Collectors.toList());
.map(this::transformMemberReviewDtoWithReviewAndTag)
.toList();

return MemberReviewsResponse.toResponse(pageDto, dtos);
}

private MemberReviewDto transformMemberReviewDtoWithReviewAndTag(final Review review) {
final List<Tag> tags = tagRepository.findTagsByReviewId(review.getId());

return MemberReviewDto.toDto(review, tags);
}

@Transactional
public void deleteReview(final Long reviewId, final Long memberId) {
final Member member = memberRepository.findById(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ class findReviewByMember_성공_테스트 {
// then
final var expectedReviews = List.of(review3_1, review2_1, review1_1);
final var expectedReviewDtos = expectedReviews.stream()
.map(MemberReviewDto::toDto)
.collect(Collectors.toList());
.map(review -> MemberReviewDto.toDto(review, Collections.emptyList()))
.toList();
final var expectedPage = new PageDto(3L, 1L, true, true, 0L, 10L);

assertThat(result.getReviews()).usingRecursiveComparison()
Expand Down
Loading