Skip to content

Commit

Permalink
Merge pull request #532 from Travel-in-nanaland/fix/#531-review
Browse files Browse the repository at this point in the history
[Feat] 이색체험 세부 카테고리로 응답되도록 수정
  • Loading branch information
jyajoo authored Dec 19, 2024
2 parents 767b1d3 + 875e867 commit 6260954
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jeju.nanaland.domain.review.dto;

import com.jeju.nanaland.domain.common.data.Category;
import com.jeju.nanaland.domain.common.dto.ImageFileDto;
import com.jeju.nanaland.domain.common.entity.ImageFile;
import com.jeju.nanaland.domain.review.entity.ReviewTypeKeyword;
Expand Down Expand Up @@ -172,8 +171,8 @@ public static class MemberReviewDetailDto {
private Long id;
@Schema(description = "장소 게시물 id")
private Long postId;
@Schema(description = "장소 카테고리(이색체험, 맛집)")
private Category category;
@Schema(description = "장소 카테고리(문화예술, 이색체험, 맛집)")
private String category;
@Schema(description = "장소명")
private String placeName;
@Schema(description = "리뷰 점수")
Expand All @@ -192,7 +191,7 @@ public static class MemberReviewDetailDto {
private Set<String> reviewTypeKeywords;

@QueryProjection
public MemberReviewDetailDto(Long id, Long postId, Category category,
public MemberReviewDetailDto(Long id, Long postId, String category,
Integer rating, String content, LocalDateTime createdAt, Long heartCount,
boolean isReviewHeart) {
this.id = id;
Expand All @@ -206,6 +205,13 @@ public MemberReviewDetailDto(Long id, Long postId, Category category,
}
}

@Getter
@AllArgsConstructor
public static class ExperienceInfo {
private String title;
private String experienceType;
}

@Getter
@Builder
@Schema(description = "회원이 작성한 리뷰 리스트 미리보기 정보")
Expand All @@ -227,8 +233,8 @@ public static class MemberReviewPreviewDetailDto {
private Long id;
@Schema(description = "장소 게시물 id")
private Long postId;
@Schema(description = "장소 카테고리(이색체험, 맛집)")
private Category category;
@Schema(description = "장소 카테고리(액티비티, 문화예술, 맛집)")
private String category;
@Schema(description = "장소명")
private String placeName;
@Schema(description = "리뷰 작성일")
Expand All @@ -239,7 +245,7 @@ public static class MemberReviewPreviewDetailDto {
private ImageFileDto imageFileDto;

@QueryProjection
public MemberReviewPreviewDetailDto(Long id, Long postId, Category category,
public MemberReviewPreviewDetailDto(Long id, Long postId, String category,
LocalDateTime createdAt, Long heartCount) {
this.id = id;
this.postId = postId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import com.jeju.nanaland.domain.review.dto.QReviewResponse_MemberReviewPreviewDetailDto;
import com.jeju.nanaland.domain.review.dto.QReviewResponse_MyReviewDetailDto;
import com.jeju.nanaland.domain.review.dto.QReviewResponse_ReviewDetailDto;
import com.jeju.nanaland.domain.review.dto.ReviewResponse.ExperienceInfo;
import com.jeju.nanaland.domain.review.dto.ReviewResponse.MemberReviewDetailDto;
import com.jeju.nanaland.domain.review.dto.ReviewResponse.MemberReviewPreviewDetailDto;
import com.jeju.nanaland.domain.review.dto.ReviewResponse.MyReviewDetailDto;
import com.jeju.nanaland.domain.review.dto.ReviewResponse.ReviewDetailDto;
import com.jeju.nanaland.domain.review.entity.ReviewTypeKeyword;
import com.querydsl.core.group.GroupBy;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.JPQLQuery;
Expand Down Expand Up @@ -203,7 +205,7 @@ public Page<MemberReviewDetailDto> findReviewListByMember(Long currentMemberId,
.select(new QReviewResponse_MemberReviewDetailDto(
review.id,
review.post.id,
review.category,
review.category.stringValue(),
review.rating,
review.content,
review.createdAt,
Expand All @@ -230,14 +232,14 @@ public Page<MemberReviewDetailDto> findReviewListByMember(Long currentMemberId,

// 2. EXPERIENCE 카테고리의 리뷰에 대한 제목 조회
List<Long> experienceIds = resultDto.stream()
.filter(dto -> dto.getCategory() == Category.EXPERIENCE)
.filter(dto -> dto.getCategory().equals(Category.EXPERIENCE.name()))
.map(MemberReviewDetailDto::getPostId)
.toList();
Map<Long, String> experienceTitleMap = fetchExperienceTitles(experienceIds, language);
Map<Long, ExperienceInfo> experienceTitleAndTypeMap = fetchExperienceTitlesAndTypes(experienceIds, language);

// 3. RESTAURANT 카테고리의 리뷰에 대한 제목 조회
List<Long> restaurantIds = resultDto.stream()
.filter(dto -> dto.getCategory() == Category.RESTAURANT)
.filter(dto -> dto.getCategory().equals(Category.RESTAURANT.name()))
.map(MemberReviewDetailDto::getPostId)
.toList();
Map<Long, String> restaurantTitleMap = fetchRestaurantTitles(restaurantIds, language);
Expand All @@ -255,14 +257,15 @@ public Page<MemberReviewDetailDto> findReviewListByMember(Long currentMemberId,
// 추가 정보를 리뷰 DTO에 설정
resultDto.forEach(
reviewDetailDto -> {
String category = reviewDetailDto.getCategory();
// 제목 설정
if (reviewDetailDto.getCategory() == Category.EXPERIENCE) {
reviewDetailDto.setPlaceName(
experienceTitleMap.getOrDefault(reviewDetailDto.getPostId(), "")
);
if (category.equals(Category.EXPERIENCE.name())) {
ExperienceInfo experienceInfo = experienceTitleAndTypeMap.get(reviewDetailDto.getPostId());
reviewDetailDto.setPlaceName(experienceInfo.getTitle());
reviewDetailDto.setCategory(experienceInfo.getExperienceType());
}

if (reviewDetailDto.getCategory() == Category.RESTAURANT) {
else if (category.equals(Category.RESTAURANT.name())) {
reviewDetailDto.setPlaceName(
restaurantTitleMap.getOrDefault(reviewDetailDto.getPostId(), "")
);
Expand Down Expand Up @@ -303,7 +306,7 @@ public List<MemberReviewPreviewDetailDto> findReviewPreviewByMember(Long current
.select(new QReviewResponse_MemberReviewPreviewDetailDto(
review.id,
review.post.id,
review.category,
review.category.stringValue(),
review.createdAt,
// 해당 리뷰의 좋아요 개수
ExpressionUtils.as(getHeartCountQuery(), "heartCount")
Expand All @@ -325,14 +328,14 @@ public List<MemberReviewPreviewDetailDto> findReviewPreviewByMember(Long current

// 2. EXPERIENCE 카테고리의 리뷰에 대한 제목 조회
List<Long> experienceIds = resultDto.stream()
.filter(dto -> dto.getCategory() == Category.EXPERIENCE)
.filter(dto -> dto.getCategory().equals(Category.EXPERIENCE.name()))
.map(MemberReviewPreviewDetailDto::getPostId)
.toList();
Map<Long, String> experienceTitleMap = fetchExperienceTitles(experienceIds, language);
Map<Long, ExperienceInfo> experienceTitleAndTypeMap = fetchExperienceTitlesAndTypes(experienceIds, language);

// 3. RESTAURANT 카테고리의 리뷰에 대한 제목 조회
List<Long> restaurantIds = resultDto.stream()
.filter(dto -> dto.getCategory() == Category.RESTAURANT)
.filter(dto -> dto.getCategory().equals(Category.RESTAURANT.name()))
.map(MemberReviewPreviewDetailDto::getPostId)
.toList();
Map<Long, String> restaurantTitleMap = fetchRestaurantTitles(restaurantIds, language);
Expand All @@ -349,13 +352,13 @@ public List<MemberReviewPreviewDetailDto> findReviewPreviewByMember(Long current
reviewImageMap.getOrDefault(reviewDetailDto.getId(), null));

// 제목 설정
if (reviewDetailDto.getCategory() == Category.EXPERIENCE) {
reviewDetailDto.setPlaceName(
experienceTitleMap.getOrDefault(reviewDetailDto.getPostId(), "")
);
if (reviewDetailDto.getCategory().equals(Category.EXPERIENCE.name())) {
ExperienceInfo experienceInfo = experienceTitleAndTypeMap.get(reviewDetailDto.getPostId());
reviewDetailDto.setPlaceName(experienceInfo.getTitle());
reviewDetailDto.setCategory(experienceInfo.getExperienceType());
}

if (reviewDetailDto.getCategory() == Category.RESTAURANT) {
if (reviewDetailDto.getCategory().equals(Category.RESTAURANT.name())) {
reviewDetailDto.setPlaceName(
restaurantTitleMap.getOrDefault(reviewDetailDto.getPostId(), "")
);
Expand Down Expand Up @@ -441,17 +444,21 @@ private Map<Long, ImageFileDto> fetchReviewImages(List<Long> reviewIds) {
}

// EXPERIENCE 카테고리의 리뷰 제목 조회
private Map<Long, String> fetchExperienceTitles(List<Long> experienceIds,
private Map<Long, ExperienceInfo> fetchExperienceTitlesAndTypes(List<Long> experienceIds,
Language language) {

return queryFactory
.select(experienceTrans.title)
.select(Projections.constructor(ExperienceInfo.class,
experienceTrans.title,
experience.experienceType.stringValue()))
.from(experience)
.innerJoin(experience.experienceTrans, experienceTrans)
.where(experience.id.in(experienceIds)
.and(experienceTrans.language.eq(language)))
.transform(GroupBy.groupBy(experience.id)
.as(experienceTrans.title));
.as(Projections.constructor(ExperienceInfo.class,
experienceTrans.title,
experience.experienceType.stringValue())));
}

// RESTAURANT 카테고리의 리뷰 제목 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.jeju.nanaland.domain.common.entity.Post;
import com.jeju.nanaland.domain.experience.entity.Experience;
import com.jeju.nanaland.domain.experience.entity.ExperienceTrans;
import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto;
import com.jeju.nanaland.domain.member.entity.Member;
import com.jeju.nanaland.domain.member.entity.enums.Provider;
Expand Down Expand Up @@ -101,6 +102,7 @@ private Experience createExperience() {
Experience experience = Experience.builder()
.firstImageFile(imageFile)
.priority((long) 1)
.experienceType(ExperienceType.ACTIVITY)
.build();
entityManager.persistAndFlush(experience);
ExperienceTrans experienceTrans = ExperienceTrans.builder()
Expand Down Expand Up @@ -228,7 +230,7 @@ void findReviewListByMember() {
MemberReviewDetailDto dto = memberReviewDetails.getContent().get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand All @@ -247,7 +249,7 @@ void findReviewListByMember2() {
MemberReviewDetailDto dto = memberReviewDetails.getContent().get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience2.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand All @@ -267,7 +269,7 @@ void findReviewListByMember3() {
MemberReviewDetailDto dto = memberReviewDetails.getContent().get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience2.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand Down Expand Up @@ -298,7 +300,7 @@ void findReviewPreviewByMember() {
MemberReviewPreviewDetailDto dto = memberReviewPreviewDetails.get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand All @@ -314,7 +316,7 @@ void findReviewPreviewByMember2() {
MemberReviewPreviewDetailDto dto = memberReviewPreviewDetails.get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience2.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand All @@ -333,7 +335,7 @@ void findReviewPreviewByMember3() {
MemberReviewPreviewDetailDto dto = memberReviewPreviewDetails.get(0);
assertThat(dto.getId()).isNotNull();
assertThat(dto.getPostId()).isEqualTo(experience2.getId());
assertThat(dto.getCategory()).isEqualTo(Category.EXPERIENCE);
assertThat(dto.getCategory()).isEqualTo(ExperienceType.ACTIVITY.name());
assertThat(dto.getPlaceName()).isEqualTo("experience title");
}

Expand All @@ -360,12 +362,4 @@ void findTotalCountByMember() {
// then
assertThat(totalCountByMember).isEqualTo(3);
}

@Test
void findExperienceMyReviewDetail() {
}

@Test
void findRestaurantMyReviewDetail() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.jeju.nanaland.domain.common.data.Language;
import com.jeju.nanaland.domain.common.dto.ImageFileDto;
import com.jeju.nanaland.domain.common.entity.ImageFile;
import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto;
import com.jeju.nanaland.domain.member.entity.Member;
import com.jeju.nanaland.domain.member.entity.enums.Provider;
Expand Down Expand Up @@ -151,7 +152,7 @@ private Page<MemberReviewDetailDto> createMemberReviewDetailList() {
MemberReviewDetailDto.builder()
.id((long) i)
.postId(1L)
.category(Category.EXPERIENCE)
.category(ExperienceType.ACTIVITY.name())
.placeName("title")
.createdAt(LocalDate.now())
.heartCount(5)
Expand All @@ -168,7 +169,7 @@ private List<MemberReviewPreviewDetailDto> createMemberReviewPreviewDetailList()
MemberReviewPreviewDetailDto.builder()
.id((long) i)
.postId(1L)
.category(Category.EXPERIENCE)
.category(ExperienceType.ACTIVITY.name())
.placeName("title")
.createdAt(LocalDate.now())
.heartCount(5)
Expand Down

0 comments on commit 6260954

Please sign in to comment.