Skip to content

Commit

Permalink
refactor: 마이페이지에 작성한 리뷰 정보 조회 변경 (#59)
Browse files Browse the repository at this point in the history
* test: 서비스 테스트 코드 수정
태그도 추가해야해서 MemberRviewDto.toDto 수정 필요

* refactor: DTO 업데이트 및 태그 정보 추가로 인한 DTO 변환 메서드 추가
  • Loading branch information
70825 authored May 24, 2024
1 parent fba171f commit b0b25f0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
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

0 comments on commit b0b25f0

Please sign in to comment.