From 49fe09ed18f75ee63a6af0b347e68646f2be94f5 Mon Sep 17 00:00:00 2001 From: seokhee Date: Fri, 20 Sep 2024 14:02:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[#397]=20refactor:=20=EC=9D=B4=EC=83=89?= =?UTF-8?q?=EC=B2=B4=ED=97=98=20dto=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ExperienceController.java | 17 ++++---- .../experience/dto/ExperienceResponse.java | 16 +++---- .../ExperienceRepositoryCustom.java | 7 +-- .../repository/ExperienceRepositoryImpl.java | 43 ++++++++++--------- .../experience/service/ExperienceService.java | 29 ++++++------- .../service/ExperienceServiceTest.java | 6 +-- 6 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java b/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java index 09898ca9..40016041 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/controller/ExperienceController.java @@ -3,8 +3,7 @@ import static com.jeju.nanaland.global.exception.SuccessCode.EXPERIENCE_DETAIL_SUCCESS; import static com.jeju.nanaland.global.exception.SuccessCode.EXPERIENCE_LIST_SUCCESS; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceDetailDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnailDto; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceTypeKeyword; import com.jeju.nanaland.domain.experience.service.ExperienceService; @@ -41,7 +40,7 @@ public class ExperienceController { @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @GetMapping("/list") - public BaseResponse getExperienceList( + public BaseResponse getExperienceList( @AuthMember MemberInfoDto memberInfoDto, @RequestParam ExperienceType experienceType, @RequestParam(defaultValue = "") List keywordFilterList, @@ -49,10 +48,10 @@ public BaseResponse getExperienceList( @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "12") int size) { - ExperienceThumbnailDto thumbnailDto = experienceService.getExperienceList(memberInfoDto, - experienceType, keywordFilterList, addressFilterList, page, size); + ExperienceResponse.PreviewPageDto previewPageDto = experienceService.getExperiencePreviews( + memberInfoDto, experienceType, keywordFilterList, addressFilterList, page, size); - return BaseResponse.success(EXPERIENCE_LIST_SUCCESS, thumbnailDto); + return BaseResponse.success(EXPERIENCE_LIST_SUCCESS, previewPageDto); } @Operation(summary = "이색체험 상세 정보 조회", description = "이색체험 상세 정보 조회") @@ -64,13 +63,13 @@ public BaseResponse getExperienceList( @ApiResponse(responseCode = "500", description = "서버측 에러", content = @Content) }) @GetMapping("/{id}") - public BaseResponse getExperienceDetail( + public BaseResponse getExperienceDetail( @AuthMember MemberInfoDto memberInfoDto, @PathVariable Long id, @RequestParam(defaultValue = "false") boolean isSearch) { - ExperienceDetailDto experienceDetail = experienceService.getExperienceDetail(memberInfoDto, + ExperienceResponse.DetailDto detailDto = experienceService.getExperienceDetail(memberInfoDto, id, isSearch); - return BaseResponse.success(EXPERIENCE_DETAIL_SUCCESS, experienceDetail); + return BaseResponse.success(EXPERIENCE_DETAIL_SUCCESS, detailDto); } } diff --git a/src/main/java/com/jeju/nanaland/domain/experience/dto/ExperienceResponse.java b/src/main/java/com/jeju/nanaland/domain/experience/dto/ExperienceResponse.java index 7fec6ea3..db29c417 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/dto/ExperienceResponse.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/dto/ExperienceResponse.java @@ -14,22 +14,22 @@ public class ExperienceResponse { @Data @Builder - @Schema(description = "이색체험 게시물 페이징 정보") - public static class ExperienceThumbnailDto { + @Schema(name = "ExperienceThumbnailDto", description = "이색체험 게시물 페이징 정보") + public static class PreviewPageDto { @Schema(description = "이색체험 전체 게시물 수") private Long totalElements; @Schema(description = "이색체험 게시물 결과 리스트") - private List data; + private List data; } @Data @Setter @Builder @AllArgsConstructor - @Schema(description = "이색체험 게시물 정보") - public static class ExperienceThumbnail { + @Schema(name = "ExperienceThumbnail", description = "이색체험 게시물 정보") + public static class PreviewDto { @Schema(description = "이색체험 게시물 id") private Long id; @@ -53,7 +53,7 @@ public static class ExperienceThumbnail { private boolean isFavorite; @QueryProjection - public ExperienceThumbnail(Long id, String originUrl, String thumbnailUrl, String title, + public PreviewDto(Long id, String originUrl, String thumbnailUrl, String title, String addressTag) { this.id = id; this.firstImage = new ImageFileDto(originUrl, thumbnailUrl); @@ -64,8 +64,8 @@ public ExperienceThumbnail(Long id, String originUrl, String thumbnailUrl, Strin @Data @Builder - @Schema(description = "이색체험 상세 정보") - public static class ExperienceDetailDto { + @Schema(name = "ExperienceDetailDto", description = "이색체험 상세 정보") + public static class DetailDto { @Schema(description = "이색체험 게시물 id") private Long id; diff --git a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java index 03624c7e..6f55c9c2 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java @@ -3,7 +3,7 @@ import com.jeju.nanaland.domain.common.data.Language; import com.jeju.nanaland.domain.common.dto.PostPreviewDto; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceTypeKeyword; import com.jeju.nanaland.domain.review.dto.ReviewResponse.SearchPostForReviewDto; @@ -19,8 +19,9 @@ public interface ExperienceRepositoryCustom { Page searchCompositeDtoByKeyword(String Keyword, Language language, Pageable pageable); - Page findExperienceThumbnails(Language language, - ExperienceType experienceType, List keywordFilterList, + Page findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + Language language, ExperienceType experienceType, + List keywordFilterList, List addressFilterList, Pageable pageable); Set getExperienceTypeKeywordSet(Long postId); diff --git a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java index 89e11631..84046abd 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java @@ -9,11 +9,10 @@ import com.jeju.nanaland.domain.common.data.Category; import com.jeju.nanaland.domain.common.data.Language; import com.jeju.nanaland.domain.common.dto.PostPreviewDto; -import com.jeju.nanaland.domain.common.dto.QPostPreviewDto; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.dto.QExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.QExperienceResponse_ExperienceThumbnail; +import com.jeju.nanaland.domain.experience.dto.QExperienceResponse_PreviewDto; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceTypeKeyword; import com.jeju.nanaland.domain.review.dto.QReviewResponse_SearchPostForReviewDto; @@ -117,12 +116,13 @@ public Page searchCompositeDtoByKeyword(String keyword, } @Override - public Page findExperienceThumbnails(Language language, - ExperienceType experienceType, List keywordFilterList, + public Page findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + Language language, ExperienceType experienceType, + List keywordFilterList, List addressFilterList, Pageable pageable) { - List resultDto = queryFactory - .selectDistinct(new QExperienceResponse_ExperienceThumbnail( + List resultDto = queryFactory + .selectDistinct(new QExperienceResponse_PreviewDto( experience.id, imageFile.originUrl, imageFile.thumbnailUrl, @@ -193,20 +193,21 @@ public List findAllIds() { @Override public PostPreviewDto findPostPreviewDto(Long postId, Language language) { - return queryFactory - .select(new QPostPreviewDto( - experience.id, - experienceTrans.title, - imageFile.originUrl, - imageFile.thumbnailUrl - )) - .from(experience) - .innerJoin(experience.experienceTrans, experienceTrans) - .innerJoin(experience.firstImageFile, imageFile) - .where( - experience.id.eq(postId), - experienceTrans.language.eq(language)) - .fetchOne(); +// return queryFactory +// .select(new QPostPreviewDto( +// experience.id, +// experienceTrans.title, +// imageFile.originUrl, +// imageFile.thumbnailUrl +// )) +// .from(experience) +// .innerJoin(experience.experienceTrans, experienceTrans) +// .innerJoin(experience.firstImageFile, imageFile) +// .where( +// experience.id.eq(postId), +// experienceTrans.language.eq(language)) +// .fetchOne(); + return null; } private List getIdListContainAllHashtags(String keyword, Language language) { diff --git a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java index 9c501b98..3974200d 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java @@ -11,9 +11,7 @@ import com.jeju.nanaland.domain.common.repository.ImageFileRepository; import com.jeju.nanaland.domain.common.service.PostService; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceDetailDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnailDto; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType; import com.jeju.nanaland.domain.experience.entity.enums.ExperienceTypeKeyword; import com.jeju.nanaland.domain.experience.repository.ExperienceRepository; @@ -80,7 +78,7 @@ public PostPreviewDto getPostPreviewDto(Long postId, Category category, Language } // 이색체험 리스트 조회 - public ExperienceThumbnailDto getExperienceList(MemberInfoDto memberInfoDto, + public ExperienceResponse.PreviewPageDto getExperiencePreviews(MemberInfoDto memberInfoDto, ExperienceType experienceType, List keywordFilterList, List addressFilterList, int page, int size) { @@ -88,29 +86,30 @@ public ExperienceThumbnailDto getExperienceList(MemberInfoDto memberInfoDto, Pageable pageable = PageRequest.of(page, size); // experienceType(액티비티, 문화예술)에 따른 이색체험 조회 - Page experienceThumbnailPage = experienceRepository.findExperienceThumbnails( - language, experienceType, keywordFilterList, addressFilterList, pageable); + Page experiencePreviewPage = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, experienceType, keywordFilterList, addressFilterList, pageable); // 좋아요 여부 List favoriteIds = memberFavoriteService.getFavoritePostIdsWithMember( memberInfoDto.getMember()); - List data = experienceThumbnailPage.getContent(); + List data = experiencePreviewPage.getContent(); // 좋아요 여부, 리뷰 평균 추가 - for (ExperienceThumbnail experienceThumbnail : data) { - Long postId = experienceThumbnail.getId(); - experienceThumbnail.setFavorite(favoriteIds.contains(postId)); - experienceThumbnail.setRatingAvg(reviewRepository.findTotalRatingAvg(EXPERIENCE, postId)); + for (ExperienceResponse.PreviewDto previewDto : data) { + Long postId = previewDto.getId(); + previewDto.setFavorite(favoriteIds.contains(postId)); + previewDto.setRatingAvg(reviewRepository.findTotalRatingAvg(EXPERIENCE, postId)); } - return ExperienceThumbnailDto.builder() - .totalElements(experienceThumbnailPage.getTotalElements()) + return ExperienceResponse.PreviewPageDto.builder() + .totalElements(experiencePreviewPage.getTotalElements()) .data(data) .build(); } // 이색체험 상세 정보 조회 - public ExperienceDetailDto getExperienceDetail(MemberInfoDto memberInfoDto, Long postId, + public ExperienceResponse.DetailDto getExperienceDetail(MemberInfoDto memberInfoDto, Long postId, boolean isSearch) { Language language = memberInfoDto.getLanguage(); @@ -144,7 +143,7 @@ public ExperienceDetailDto getExperienceDetail(MemberInfoDto memberInfoDto, Long experienceTypeKeyword.getValueByLocale(language) ).toList(); - return ExperienceDetailDto.builder() + return ExperienceResponse.DetailDto.builder() .id(experienceCompositeDto.getId()) .title(experienceCompositeDto.getTitle()) .intro(experienceCompositeDto.getIntro()) diff --git a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java index c639b2c8..b9f2c071 100644 --- a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java @@ -14,7 +14,7 @@ import com.jeju.nanaland.domain.common.entity.Post; import com.jeju.nanaland.domain.common.repository.ImageFileRepository; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceDetailDto; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnailDto; import com.jeju.nanaland.domain.experience.entity.Experience; @@ -126,8 +126,8 @@ void getActivityList() { .findPostImageFiles(postId); // when - ExperienceDetailDto result = experienceService.getExperienceDetail(memberInfoDto, postId, - false); + ExperienceResponse.DetailDto result = + experienceService.getExperienceDetail(memberInfoDto, postId, false); // then assertThat(result).extracting("title").isEqualTo("액티비티 테스트 제목1"); From c412b95090e874eeb49e797ad6f62aaa05687e18 Mon Sep 17 00:00:00 2001 From: seokhee Date: Fri, 20 Sep 2024 14:27:23 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[#397]=20refactor:=20javadoc=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExperienceRepositoryCustom.java | 2 +- .../repository/ExperienceRepositoryImpl.java | 105 ++++++++++-------- .../experience/service/ExperienceService.java | 26 ++++- 3 files changed, 80 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java index 6f55c9c2..8a032ff2 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryCustom.java @@ -14,7 +14,7 @@ public interface ExperienceRepositoryCustom { - ExperienceCompositeDto findCompositeDtoById(Long id, Language language); + ExperienceCompositeDto findExperienceCompositeDto(Long id, Language language); Page searchCompositeDtoByKeyword(String Keyword, Language language, Pageable pageable); diff --git a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java index 84046abd..c6879148 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryImpl.java @@ -9,6 +9,7 @@ import com.jeju.nanaland.domain.common.data.Category; import com.jeju.nanaland.domain.common.data.Language; import com.jeju.nanaland.domain.common.dto.PostPreviewDto; +import com.jeju.nanaland.domain.common.dto.QPostPreviewDto; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.dto.QExperienceCompositeDto; @@ -38,7 +39,7 @@ public class ExperienceRepositoryImpl implements ExperienceRepositoryCustom { private final JPAQueryFactory queryFactory; @Override - public ExperienceCompositeDto findCompositeDtoById(Long id, Language language) { + public ExperienceCompositeDto findExperienceCompositeDto(Long id, Language language) { return queryFactory .select(new QExperienceCompositeDto( experience.id, @@ -60,7 +61,10 @@ public ExperienceCompositeDto findCompositeDtoById(Long id, Language language) { .from(experience) .leftJoin(experience.firstImageFile, imageFile) .leftJoin(experience.experienceTrans, experienceTrans) - .where(experience.id.eq(id).and(experienceTrans.language.eq(language))) + .where( + experience.id.eq(id), + experienceTrans.language.eq(language) + ) .fetchOne(); } @@ -92,10 +96,12 @@ public Page searchCompositeDtoByKeyword(String keyword, .leftJoin(experience.firstImageFile, imageFile) .leftJoin(experience.experienceTrans, experienceTrans) .on(experienceTrans.language.eq(language)) - .where(experienceTrans.title.contains(keyword) - .or(experienceTrans.addressTag.contains(keyword)) - .or(experienceTrans.content.contains(keyword)) - .or(experience.id.in(idListContainAllHashtags))) + .where( + experienceTrans.title.contains(keyword) + .or(experienceTrans.addressTag.contains(keyword)) + .or(experienceTrans.content.contains(keyword)) + .or(experience.id.in(idListContainAllHashtags)) + ) .orderBy(experienceTrans.createdAt.desc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) @@ -107,10 +113,12 @@ public Page searchCompositeDtoByKeyword(String keyword, .leftJoin(experience.firstImageFile, imageFile) .leftJoin(experience.experienceTrans, experienceTrans) .on(experienceTrans.language.eq(language)) - .where(experienceTrans.title.contains(keyword) - .or(experienceTrans.addressTag.contains(keyword)) - .or(experienceTrans.content.contains(keyword)) - .or(experience.id.in(idListContainAllHashtags))); + .where( + experienceTrans.title.contains(keyword) + .or(experienceTrans.addressTag.contains(keyword)) + .or(experienceTrans.content.contains(keyword)) + .or(experience.id.in(idListContainAllHashtags)) + ); return PageableExecutionUtils.getPage(resultDto, pageable, countQuery::fetchOne); } @@ -134,12 +142,16 @@ public Page findAllExperiencePreviewDtoOrderByPri .innerJoin(experience.experienceTrans, experienceTrans) .innerJoin(experienceKeyword) .on(experienceKeyword.experience.id.eq(experience.id)) - .where(experienceTrans.language.eq(language) - .and(experience.experienceType.eq(experienceType)) // 이색체험 타입(액티비티/문화예술) - .and(addressTagCondition(addressFilterList)) // 지역필터 - .and(keywordCondition(keywordFilterList))) // 키워드 필터 - .orderBy(experience.priority.desc(), // 우선순위 정렬 - experience.createdAt.desc()) // 최신순 정렬 + .where( + experienceTrans.language.eq(language), + experience.experienceType.eq(experienceType), // 이색체험 타입(액티비티/문화예술) + addressTagCondition(addressFilterList), // 지역필터 + keywordCondition(keywordFilterList) // 키워드 필터 + ) + .orderBy( + experience.priority.desc(), // 우선순위 정렬 + experience.createdAt.desc() // 최신순 정렬 + ) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetch(); @@ -151,10 +163,12 @@ public Page findAllExperiencePreviewDtoOrderByPri .innerJoin(experience.experienceTrans, experienceTrans) .innerJoin(experienceKeyword) .on(experienceKeyword.experience.id.eq(experience.id)) - .where(experienceTrans.language.eq(language) - .and(experience.experienceType.eq(experienceType)) - .and(addressTagCondition(addressFilterList)) - .and(keywordCondition(keywordFilterList))); + .where( + experienceTrans.language.eq(language), + experience.experienceType.eq(experienceType), + addressTagCondition(addressFilterList), + keywordCondition(keywordFilterList) + ); return PageableExecutionUtils.getPage(resultDto, pageable, countQuery::fetchOne); } @@ -193,21 +207,20 @@ public List findAllIds() { @Override public PostPreviewDto findPostPreviewDto(Long postId, Language language) { -// return queryFactory -// .select(new QPostPreviewDto( -// experience.id, -// experienceTrans.title, -// imageFile.originUrl, -// imageFile.thumbnailUrl -// )) -// .from(experience) -// .innerJoin(experience.experienceTrans, experienceTrans) -// .innerJoin(experience.firstImageFile, imageFile) -// .where( -// experience.id.eq(postId), -// experienceTrans.language.eq(language)) -// .fetchOne(); - return null; + return queryFactory + .select(new QPostPreviewDto( + experience.id, + experienceTrans.title, + imageFile.originUrl, + imageFile.thumbnailUrl + )) + .from(experience) + .innerJoin(experience.experienceTrans, experienceTrans) + .innerJoin(experience.firstImageFile, imageFile) + .where( + experience.id.eq(postId), + experienceTrans.language.eq(language)) + .fetchOne(); } private List getIdListContainAllHashtags(String keyword, Language language) { @@ -215,12 +228,13 @@ private List getIdListContainAllHashtags(String keyword, Language language .select(experience.id) .from(experience) .leftJoin(hashtag) - .on(hashtag.post.id.eq(experience.id) - .and(hashtag.category.eq(Category.EXPERIENCE)) - .and(hashtag.language.eq(language))) + .on(hashtag.post.id.eq(experience.id), + hashtag.category.eq(Category.EXPERIENCE), + hashtag.language.eq(language) + ) .where(hashtag.keyword.content.in(splitKeyword(keyword))) .groupBy(experience.id) - .having(experience.id.count().eq(splitKeyword(keyword).stream().count())) + .having(experience.id.count().eq((long) splitKeyword(keyword).size())) .fetch(); } @@ -235,18 +249,11 @@ private List splitKeyword(String keyword) { } private BooleanExpression addressTagCondition(List addressFilterList) { - if (addressFilterList.isEmpty()) { - return null; - } else { - return experienceTrans.addressTag.in(addressFilterList); - } + return addressFilterList.isEmpty() ? null : experienceTrans.addressTag.in(addressFilterList); } private BooleanExpression keywordCondition(List keywordFilterList) { - if (keywordFilterList.isEmpty()) { - return null; - } else { - return experienceKeyword.experienceTypeKeyword.in(keywordFilterList); - } + return keywordFilterList.isEmpty() ? null + : experienceKeyword.experienceTypeKeyword.in(keywordFilterList); } } diff --git a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java index 3974200d..5f5c27a8 100644 --- a/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java +++ b/src/main/java/com/jeju/nanaland/domain/experience/service/ExperienceService.java @@ -77,7 +77,20 @@ public PostPreviewDto getPostPreviewDto(Long postId, Category category, Language return postPreviewDto; } - // 이색체험 리스트 조회 + /** + * 이색체험 리스트 조회 + * + * @param memberInfoDto 회원 정보 + * @param experienceType 이색체험 타입 (ACTIVITY, CULTURE_AND_ARTS) + * @param keywordFilterList 키워드 필터 (LAND_LEISURE, WATER_LEISURE, AIR_LEISURE, MARINE_EXPERIENCE, + * RURAL_EXPERIENCE, HEALING_THERAPY, HISTORY, EXHIBITION, WORKSHOP, + * ART_MUSEUM, MUSEUM, PARK, PERFORMANCE, RELIGIOUS_FACILITY, + * THEME_PARK) + * @param addressFilterList 지역 필터 + * @param page 페이지 + * @param size 페이지 크기 + * @return ExperienceResponse.PreviewPageDto + */ public ExperienceResponse.PreviewPageDto getExperiencePreviews(MemberInfoDto memberInfoDto, ExperienceType experienceType, List keywordFilterList, List addressFilterList, int page, int size) { @@ -108,12 +121,19 @@ public ExperienceResponse.PreviewPageDto getExperiencePreviews(MemberInfoDto mem .build(); } - // 이색체험 상세 정보 조회 + /** + * 이색체험 상세정보 조회 + * + * @param memberInfoDto 회원 정보 + * @param postId 게시물 id + * @param isSearch 검색을 통해 들어왔는지 여부 + * @return ExperienceResponse.DetailDto + */ public ExperienceResponse.DetailDto getExperienceDetail(MemberInfoDto memberInfoDto, Long postId, boolean isSearch) { Language language = memberInfoDto.getLanguage(); - ExperienceCompositeDto experienceCompositeDto = experienceRepository.findCompositeDtoById( + ExperienceCompositeDto experienceCompositeDto = experienceRepository.findExperienceCompositeDto( postId, language); // 해당 id의 포스트가 없는 경우 404 에러 From 6f49400f156648b8a47e0d95c4b2ae54e97f2e9c Mon Sep 17 00:00:00 2001 From: seokhee Date: Fri, 20 Sep 2024 16:06:56 +0900 Subject: [PATCH 3/4] [#397] refactor: experienceRepositoryTest --- .../member/service/MemberTypeService.java | 5 +- .../domain/report/service/ReportService.java | 8 +- .../domain/search/service/SearchService.java | 2 +- .../repository/ExperienceRepositoryTest.java | 273 ++++++++++++------ .../service/ExperienceServiceTest.java | 19 +- 5 files changed, 196 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/jeju/nanaland/domain/member/service/MemberTypeService.java b/src/main/java/com/jeju/nanaland/domain/member/service/MemberTypeService.java index 0f113b72..8acd821a 100644 --- a/src/main/java/com/jeju/nanaland/domain/member/service/MemberTypeService.java +++ b/src/main/java/com/jeju/nanaland/domain/member/service/MemberTypeService.java @@ -6,10 +6,9 @@ import com.jeju.nanaland.domain.common.data.Language; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; import com.jeju.nanaland.domain.experience.repository.ExperienceRepository; +import com.jeju.nanaland.domain.favorite.service.MemberFavoriteService; import com.jeju.nanaland.domain.member.dto.MemberRequest; import com.jeju.nanaland.domain.member.dto.MemberResponse; -import com.jeju.nanaland.domain.favorite.service.MemberFavoriteService; -import com.jeju.nanaland.domain.member.dto.MemberRequest.UpdateTypeDto; import com.jeju.nanaland.domain.member.dto.MemberResponse.MemberInfoDto; import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.Recommend; @@ -167,7 +166,7 @@ private MemberResponse.RecommendPostDto getRecommendPostDto(Member member, Long private MemberResponse.RecommendPostDto getExperiencePostDto(Member member, Long postId, Language language) { - ExperienceCompositeDto compositeDto = experienceRepository.findCompositeDtoById(postId, + ExperienceCompositeDto compositeDto = experienceRepository.findExperienceCompositeDto(postId, language); MemberResponse.RecommendPostDto recommendPostDto = MemberResponse.RecommendPostDto.builder() .id(compositeDto.getId()) diff --git a/src/main/java/com/jeju/nanaland/domain/report/service/ReportService.java b/src/main/java/com/jeju/nanaland/domain/report/service/ReportService.java index a0453ae9..050f34fd 100644 --- a/src/main/java/com/jeju/nanaland/domain/report/service/ReportService.java +++ b/src/main/java/com/jeju/nanaland/domain/report/service/ReportService.java @@ -25,15 +25,15 @@ import com.jeju.nanaland.domain.report.dto.ReportRequest; import com.jeju.nanaland.domain.report.dto.ReportRequest.ClaimReportDto; import com.jeju.nanaland.domain.report.dto.ReportRequest.InfoFixDto; -import com.jeju.nanaland.domain.report.entity.infoFix.FixType; -import com.jeju.nanaland.domain.report.entity.infoFix.InfoFixReport; import com.jeju.nanaland.domain.report.entity.Report; -import com.jeju.nanaland.domain.report.entity.ReportStrategyFactory; import com.jeju.nanaland.domain.report.entity.ReportStrategy; +import com.jeju.nanaland.domain.report.entity.ReportStrategyFactory; import com.jeju.nanaland.domain.report.entity.claim.ClaimReport; import com.jeju.nanaland.domain.report.entity.claim.ClaimReportType; import com.jeju.nanaland.domain.report.entity.claim.ClaimReportVideoFile; import com.jeju.nanaland.domain.report.entity.claim.ClaimType; +import com.jeju.nanaland.domain.report.entity.infoFix.FixType; +import com.jeju.nanaland.domain.report.entity.infoFix.InfoFixReport; import com.jeju.nanaland.domain.report.repository.ClaimReportRepository; import com.jeju.nanaland.domain.report.repository.ClaimReportVideoFileRepository; import com.jeju.nanaland.domain.report.repository.InfoFixReportRepository; @@ -163,7 +163,7 @@ private CompositeDto findCompositeDto(Category category, Long postId, Language l case NATURE -> natureRepository.findNatureCompositeDto(postId, language); case MARKET -> marketRepository.findCompositeDtoById(postId, language); case FESTIVAL -> festivalRepository.findCompositeDtoById(postId, language); - case EXPERIENCE -> experienceRepository.findCompositeDtoById(postId, language); + case EXPERIENCE -> experienceRepository.findExperienceCompositeDto(postId, language); case RESTAURANT -> restaurantRepository.findCompositeDtoById(postId, language); default -> null; }; diff --git a/src/main/java/com/jeju/nanaland/domain/search/service/SearchService.java b/src/main/java/com/jeju/nanaland/domain/search/service/SearchService.java index 0a28702a..dd54518d 100644 --- a/src/main/java/com/jeju/nanaland/domain/search/service/SearchService.java +++ b/src/main/java/com/jeju/nanaland/domain/search/service/SearchService.java @@ -386,7 +386,7 @@ public List getTopSearchVolumePosts(MemberInfoDto memberInfoDto getSearchVolumeDto(memberInfoDto, categoryContent, marketCompositeDto)); } case EXPERIENCE -> { - CompositeDto experienceCompositeDto = experienceRepository.findCompositeDtoById( + CompositeDto experienceCompositeDto = experienceRepository.findExperienceCompositeDto( postId, memberInfoDto.getLanguage()); searchVolumeDtoList.add( diff --git a/src/test/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryTest.java b/src/test/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryTest.java index d02564f3..4503f41a 100644 --- a/src/test/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryTest.java +++ b/src/test/java/com/jeju/nanaland/domain/experience/repository/ExperienceRepositoryTest.java @@ -10,7 +10,7 @@ import com.jeju.nanaland.domain.common.data.Language; import com.jeju.nanaland.domain.common.entity.ImageFile; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; +import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; import com.jeju.nanaland.domain.experience.entity.Experience; import com.jeju.nanaland.domain.experience.entity.ExperienceKeyword; import com.jeju.nanaland.domain.experience.entity.ExperienceTrans; @@ -19,8 +19,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.UUID; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; @@ -41,74 +44,160 @@ class ExperienceRepositoryTest { @Autowired ExperienceRepository experienceRepository; - @Test - @DisplayName("이색체험 상세조회") - void findCompositeDtoByIdTest() { + @ParameterizedTest + @EnumSource(value = Language.class) + @DisplayName("액티비티 상세조회") + void findActivityExperienceCompositeDtoTest(Language language) { // given - Language language = Language.KOREAN; - // 지상레저 이색체험 게시물 1개 생성 - List experienceList = - getActivityList(language, List.of(LAND_LEISURE), "서귀포시", 1); + // 역사 키워드 문화예술 게시물 1개 생성 + Experience experience = createExperience(ExperienceType.ACTIVITY); + ExperienceTrans experienceTrans = createExperienceTrans(experience, language, + List.of(LAND_LEISURE), "제주시"); + Long postId = experience.getId(); // when - ExperienceCompositeDto result = experienceRepository.findCompositeDtoById( - experienceList.get(0).getId(), language); + ExperienceCompositeDto result = experienceRepository.findExperienceCompositeDto( + postId, language); // then - assertThat(result.getTitle()).isEqualTo("activity title 1"); + assertThat(result.getTitle()).isEqualTo(experienceTrans.getTitle()); + } + + @ParameterizedTest + @EnumSource(value = Language.class) + @DisplayName("문화예술 상세조회") + void findCultureAndArtsExperienceCompositeDtoTest(Language language) { + // given + // 역사 키워드 문화예술 게시물 1개 생성 + Experience experience = createExperience(ExperienceType.CULTURE_AND_ARTS); + ExperienceTrans experienceTrans = createExperienceTrans(experience, language, List.of(HISTORY), + "제주시"); + Long postId = experience.getId(); + + // when + ExperienceCompositeDto result = experienceRepository.findExperienceCompositeDto( + postId, language); + + // then + assertThat(result.getTitle()).isEqualTo(experienceTrans.getTitle()); } @Test @DisplayName("액티비티 리스트 조회 - 키워드 필터") - void findActivityThumbnailsWithKeywordFilterTest() { + void findAllActivityPreviewDtosWithKeywordFilterTest() { // given Language language = Language.KOREAN; Pageable pageable = PageRequest.of(0, 12); - List experienceList = new ArrayList<>(); - experienceList.addAll( // 액티비티 - 지상레저 2개 - getActivityList(language, List.of(LAND_LEISURE), "제주시", 2)); - experienceList.addAll( // 액티비티 - 수상레저 3개 - getActivityList(language, List.of(WATER_LEISURE), "서귀포시", 3)); - experienceList.addAll( // 문화예술 - 역사, 박물관 1개 - getCultureAndArtsList(language, List.of(HISTORY, MUSEUM), "제주시", 1)); + // 액티비티 - 지상레저 2개 + createActivities(language, List.of(LAND_LEISURE), "제주시", 2); + // 액티비티 - 수상레저 3개 + createActivities(language, List.of(WATER_LEISURE), "서귀포시", 3); // when - Page result = experienceRepository.findExperienceThumbnails(language, - ExperienceType.ACTIVITY, List.of(LAND_LEISURE), List.of(), pageable); + // 액티비티 - 지상레저 + Page landLeisureResult = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.ACTIVITY, List.of(LAND_LEISURE), List.of(), pageable); + // 액티비티 - 지상레저, 수상레저 + Page landAndWaterLeisureResult = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.ACTIVITY, List.of(LAND_LEISURE, WATER_LEISURE), List.of(), + pageable); // then - assertThat(result.getTotalElements()).isEqualTo(2); + assertThat(landLeisureResult.getTotalElements()).isEqualTo(2); + assertThat(landAndWaterLeisureResult.getTotalElements()).isEqualTo(5); } @Test @DisplayName("액티비티 리스트 조회 - 지역 필터") - void findActivityThumbnailsWithAddressFilterTest() { + void findAllActivityPreviewDtosWithAddressFilterTest() { // given Language language = Language.KOREAN; Pageable pageable = PageRequest.of(0, 12); - List experienceList = new ArrayList<>(); - experienceList.addAll( // 액티비티 - 지상레저 2개 - getActivityList(language, List.of(LAND_LEISURE), "제주시", 2)); - experienceList.addAll( // 액티비티 - 수상레저 2개 - getActivityList(language, List.of(WATER_LEISURE), "서귀포시", 2)); - experienceList.addAll( // 문화예술 - 역사, 박물관 1개 - getCultureAndArtsList(language, List.of(HISTORY, MUSEUM), "제주시", 1)); + // 액티비티 - 지상레저 2개 + createActivities(language, List.of(LAND_LEISURE), "제주시", 2); + // 액티비티 - 수상레저 3개 + createActivities(language, List.of(WATER_LEISURE), "서귀포시", 3); + + // when + // 액티비티 - 지상레저 + Page result1 = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.ACTIVITY, List.of(), List.of("제주시"), pageable); + // 액티비티 - 지상레저, 수상레저 + Page result2 = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.ACTIVITY, List.of(), List.of("제주시", "서귀포시"), + pageable); + + // then + assertThat(result1.getTotalElements()).isEqualTo(2); + assertThat(result2.getTotalElements()).isEqualTo(5); + } + + @Test + @DisplayName("문화예술 리스트 조회 - 키워드 필터") + void findAllCultureAndArtsPreviewDtosWithKeywordFilterTest() { + // given + Language language = Language.KOREAN; + Pageable pageable = PageRequest.of(0, 12); + // 문화예술 - 역사 2개 + createCultureAndArts(language, List.of(HISTORY), "제주시", 2); + // 문화예술 - 역사, 박물관 3개 + createCultureAndArts(language, List.of(HISTORY, MUSEUM), "서귀포시", 3); + + // when + // 문화예술 - 역사 + Page historyResult = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.CULTURE_AND_ARTS, List.of(HISTORY), List.of(), pageable); + // 액티비티 - 박물관 + Page museumResult = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.CULTURE_AND_ARTS, List.of(MUSEUM), List.of(), pageable); + + // then + assertThat(historyResult.getTotalElements()).isEqualTo(5); + assertThat(museumResult.getTotalElements()).isEqualTo(3); + } + + @Test + @DisplayName("문화예술 리스트 조회 - 지역 필터") + void findAllCultureAndArtsPreviewDtosWithAddressFilterTest() { + // given + Language language = Language.KOREAN; + Pageable pageable = PageRequest.of(0, 12); + // 문화예술 - 제주시 2개 + createCultureAndArts(language, List.of(HISTORY), "제주시", 2); + // 문화예술 - 서귀포시 3개 + createCultureAndArts(language, List.of(HISTORY), "서귀포시", 3); // when - Page result = experienceRepository.findExperienceThumbnails(language, - ExperienceType.ACTIVITY, List.of(), List.of("서귀포시"), pageable); + // 문화예술 - 전체 + Page result1 = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.CULTURE_AND_ARTS, List.of(), List.of(), pageable); + // 문화예술 - 제주시 + Page result2 = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.CULTURE_AND_ARTS, List.of(), List.of("제주시"), pageable); + // 액티비티 - 서귀포시 + Page result3 = + experienceRepository.findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc( + language, ExperienceType.CULTURE_AND_ARTS, List.of(), List.of("서귀포시"), pageable); // then - assertThat(result.getTotalElements()).isEqualTo(2); - assertThat(result.getContent()).extracting("addressTag") - .containsOnly("서귀포시"); + assertThat(result1.getTotalElements()).isEqualTo(5); + assertThat(result2.getTotalElements()).isEqualTo(2); + assertThat(result3.getTotalElements()).isEqualTo(3); } @Test @DisplayName("이색체험 키워드 조회") void getExperienceTypeKeywordSetTest() { // given - Experience experience = getActivityList(Language.KOREAN, + Experience experience = createActivities(Language.KOREAN, List.of(LAND_LEISURE, WATER_LEISURE, HISTORY), "제주시", 1).get(0); // when @@ -125,36 +214,58 @@ void getExperienceTypeKeywordSetTest() { ); } - private List getActivityList(Language language, - List keywordList, String addressTag, int size) { - List experienceList = new ArrayList<>(); - for (int i = 1; i <= size; i++) { - ImageFile imageFile = ImageFile.builder() - .originUrl("originUrl" + i) - .thumbnailUrl("thumbnailUrl" + i) - .build(); - em.persist(imageFile); - Experience experience = Experience.builder() - .firstImageFile(imageFile) - .priority(0L) - .experienceType(ExperienceType.ACTIVITY) - .build(); - em.persistAndFlush(experience); - ExperienceTrans experienceTrans = ExperienceTrans.builder() + private ImageFile createImageFile() { + ImageFile imageFile = ImageFile + .builder() + .originUrl(UUID.randomUUID().toString()) + .thumbnailUrl(UUID.randomUUID().toString()) + .build(); + em.persist(imageFile); + + return imageFile; + } + + private Experience createExperience(ExperienceType experienceType) { + ImageFile newImageFile = createImageFile(); + + Experience newExperience = Experience.builder() + .priority(0L) + .firstImageFile(newImageFile) + .experienceType(experienceType) + .build(); + em.persist(newExperience); + + return newExperience; + } + + private ExperienceTrans createExperienceTrans(Experience experience, Language language, + List keywordList, String addressTag) { + ExperienceTrans experienceTrans = ExperienceTrans.builder() + .experience(experience) + .language(language) + .addressTag(addressTag) + .title(UUID.randomUUID().toString()) + .build(); + em.persist(experienceTrans); + + for (ExperienceTypeKeyword keyword : keywordList) { + ExperienceKeyword experienceKeyword = ExperienceKeyword.builder() + .experienceTypeKeyword(keyword) .experience(experience) - .title("activity title " + i) - .language(language) - .addressTag(addressTag) .build(); - em.persist(experienceTrans); + em.persist(experienceKeyword); + } - for (ExperienceTypeKeyword keyword : keywordList) { - ExperienceKeyword experienceKeyword = ExperienceKeyword.builder() - .experienceTypeKeyword(keyword) - .experience(experience) - .build(); - em.persist(experienceKeyword); - } + return experienceTrans; + } + + private List createActivities(Language language, + List keywordList, String addressTag, int size) { + List experienceList = new ArrayList<>(); + for (int i = 1; i <= size; i++) { + Experience experience = createExperience(ExperienceType.ACTIVITY); + createExperienceTrans(experience, language, keywordList, + addressTag); experienceList.add(experience); } @@ -162,40 +273,16 @@ private List getActivityList(Language language, return experienceList; } - private List getCultureAndArtsList(Language language, + private List createCultureAndArts(Language language, List keywordList, String addressTag, int size) { - List cultureAndArtsList = new ArrayList<>(); + List experienceList = new ArrayList<>(); for (int i = 1; i <= size; i++) { - ImageFile imageFile = ImageFile.builder() - .originUrl("originUrl" + i) - .thumbnailUrl("thumbnailUrl" + i) - .build(); - em.persist(imageFile); - Experience experience = Experience.builder() - .firstImageFile(imageFile) - .priority(0L) - .experienceType(ExperienceType.CULTURE_AND_ARTS) - .build(); - em.persistAndFlush(experience); - ExperienceTrans experienceTrans = ExperienceTrans.builder() - .experience(experience) - .title("culture and arts title " + i) - .language(language) - .addressTag(addressTag) - .build(); - em.persist(experienceTrans); + Experience experience = createExperience(ExperienceType.CULTURE_AND_ARTS); + createExperienceTrans(experience, language, keywordList, addressTag); - for (ExperienceTypeKeyword keyword : keywordList) { - ExperienceKeyword experienceKeyword = ExperienceKeyword.builder() - .experienceTypeKeyword(keyword) - .experience(experience) - .build(); - em.persist(experienceKeyword); - } - - cultureAndArtsList.add(experience); + experienceList.add(experience); } - return cultureAndArtsList; + return experienceList; } } \ No newline at end of file diff --git a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java index b9f2c071..b89548a2 100644 --- a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java @@ -15,8 +15,6 @@ import com.jeju.nanaland.domain.common.repository.ImageFileRepository; import com.jeju.nanaland.domain.experience.dto.ExperienceCompositeDto; import com.jeju.nanaland.domain.experience.dto.ExperienceResponse; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnail; -import com.jeju.nanaland.domain.experience.dto.ExperienceResponse.ExperienceThumbnailDto; 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; @@ -119,7 +117,7 @@ void getActivityList() { .build(); doReturn(experienceCompositeDto).when(experienceRepository) - .findCompositeDtoById(postId, language); + .findExperienceCompositeDto(postId, language); doReturn(false).when(memberFavoriteService) .isPostInFavorite(memberInfoDto.getMember(), Category.EXPERIENCE, postId); doReturn(List.of()).when(imageFileRepository) // 빈 이미지 리스트 @@ -144,28 +142,29 @@ void getExperienceListTest() { List experienceList = new ArrayList<>(); experienceList.addAll(getActivityList(language, "제주시", 2)); experienceList.addAll(getActivityList(language, "제주시", 3)); - List experienceThumbnailList = List.of( - ExperienceThumbnail.builder() + List experienceThumbnailList = List.of( + ExperienceResponse.PreviewDto.builder() .title("title 1") .build(), - ExperienceThumbnail.builder() + ExperienceResponse.PreviewDto.builder() .title("title 2") .build() ); - Page experienceThumbnailPage = + Page experienceThumbnailPage = new PageImpl<>( experienceThumbnailList, pageable, experienceThumbnailList.size()); doReturn(experienceThumbnailPage).when(experienceRepository) - .findExperienceThumbnails(language, ExperienceType.ACTIVITY, List.of(), List.of(), - pageable); + .findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc(language, + ExperienceType.ACTIVITY, List.of(), List.of(), pageable); doReturn(4.32).when(reviewRepository) .findTotalRatingAvg(Category.EXPERIENCE, null); // when - ExperienceThumbnailDto result = experienceService.getExperienceList(memberInfoDto, + ExperienceResponse.PreviewPageDto result = experienceService.getExperiencePreviews( + memberInfoDto, ExperienceType.ACTIVITY, List.of(), List.of(), 0, 12); // then From b449cd66f88d6c303f21a14791810fa169670eec Mon Sep 17 00:00:00 2001 From: seokhee Date: Fri, 20 Sep 2024 17:03:36 +0900 Subject: [PATCH 4/4] [#397] refactor: experienceServiceTest --- .../service/ExperienceServiceTest.java | 157 ++++++++---------- 1 file changed, 73 insertions(+), 84 deletions(-) diff --git a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java index b89548a2..3189449c 100644 --- a/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java +++ b/src/test/java/com/jeju/nanaland/domain/experience/service/ExperienceServiceTest.java @@ -24,7 +24,6 @@ import com.jeju.nanaland.domain.member.entity.Member; import com.jeju.nanaland.domain.member.entity.enums.TravelType; import com.jeju.nanaland.domain.review.repository.ReviewRepository; -import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -33,6 +32,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -58,26 +59,26 @@ class ExperienceServiceTest { @Mock ReviewRepository reviewRepository; - @Test + @ParameterizedTest + @EnumSource(value = Language.class) @DisplayName("이색체험 preview 정보 조회") - void getPostCardDtoTest() { + void getPostCardDtoTest(Language language) { // given ImageFile imageFile = createImageFile(); - Experience experience = createExperience(imageFile); - ExperienceTrans experienceTrans = createExperienceTrans(experience); + Experience experience = createExperience(imageFile, ExperienceType.ACTIVITY); + ExperienceTrans experienceTrans = createExperienceTrans(language, experience); PostPreviewDto postPreviewDto = PostPreviewDto.builder() .firstImage(new ImageFileDto(imageFile.getOriginUrl(), imageFile.getThumbnailUrl())) .title(experienceTrans.getTitle()) .id(experience.getId()) .category(Category.EXPERIENCE.toString()) .build(); - when(experienceRepository.findPostPreviewDto(nullable(Long.class), eq(Language.KOREAN))) + when(experienceRepository.findPostPreviewDto(nullable(Long.class), eq(language))) .thenReturn(postPreviewDto); // when PostPreviewDto result = - experienceService.getPostPreviewDto(postPreviewDto.getId(), Category.MARKET, - Language.KOREAN); + experienceService.getPostPreviewDto(postPreviewDto.getId(), Category.EXPERIENCE, language); // then assertThat(result.getFirstImage()).isEqualTo(postPreviewDto.getFirstImage()); @@ -97,23 +98,21 @@ void getPostTest() { .thenReturn(Optional.ofNullable(experience)); // when - Post post = experienceService.getPost(1L, Category.MARKET); + Post post = experienceService.getPost(1L, Category.EXPERIENCE); // then assertThat(post.getFirstImageFile()).isEqualTo(imageFile); } @Test - @DisplayName("액티비티 상세조회") - void getActivityList() { + @DisplayName("이색체험 상세조회") + void getExperienceDetailTest() { // given - ExperienceType experienceType = ExperienceType.ACTIVITY; Language language = Language.KOREAN; MemberInfoDto memberInfoDto = getMemberInfoDto(language, TravelType.NONE); Long postId = 1L; - List experienceList = getActivityList(language, "제주시", 1); ExperienceCompositeDto experienceCompositeDto = ExperienceCompositeDto.builder() - .title("액티비티 테스트 제목1") + .title(UUID.randomUUID().toString()) .build(); doReturn(experienceCompositeDto).when(experienceRepository) @@ -128,35 +127,34 @@ void getActivityList() { experienceService.getExperienceDetail(memberInfoDto, postId, false); // then - assertThat(result).extracting("title").isEqualTo("액티비티 테스트 제목1"); + assertThat(result.getTitle()).isEqualTo(experienceCompositeDto.getTitle()); } - @Test + @ParameterizedTest + @EnumSource(value = Language.class) @DisplayName("액티비티 리스트 조회") - void getExperienceListTest() { + void getActivitiesTest(Language language) { // given - ExperienceType experienceType = ExperienceType.ACTIVITY; - Language language = Language.KOREAN; MemberInfoDto memberInfoDto = getMemberInfoDto(language, TravelType.NONE); Pageable pageable = PageRequest.of(0, 12); - List experienceList = new ArrayList<>(); - experienceList.addAll(getActivityList(language, "제주시", 2)); - experienceList.addAll(getActivityList(language, "제주시", 3)); - List experienceThumbnailList = List.of( + + List previewDtos = List.of( ExperienceResponse.PreviewDto.builder() - .title("title 1") + .title(UUID.randomUUID().toString()) + .addressTag("제주시") .build(), ExperienceResponse.PreviewDto.builder() - .title("title 2") + .title(UUID.randomUUID().toString()) + .addressTag("서귀포시") .build() ); - Page experienceThumbnailPage = + Page previewPage = new PageImpl<>( - experienceThumbnailList, + previewDtos, pageable, - experienceThumbnailList.size()); + previewDtos.size()); - doReturn(experienceThumbnailPage).when(experienceRepository) + doReturn(previewPage).when(experienceRepository) .findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc(language, ExperienceType.ACTIVITY, List.of(), List.of(), pageable); doReturn(4.32).when(reviewRepository) @@ -164,11 +162,50 @@ void getExperienceListTest() { // when ExperienceResponse.PreviewPageDto result = experienceService.getExperiencePreviews( - memberInfoDto, - ExperienceType.ACTIVITY, List.of(), List.of(), 0, 12); + memberInfoDto, ExperienceType.ACTIVITY, List.of(), List.of(), 0, 12); // then - assertThat(result.getTotalElements()).isEqualTo(2); + assertThat(result.getTotalElements()).isEqualTo(previewDtos.size()); + assertThat(result.getData()).isEqualTo(previewDtos); + } + + @ParameterizedTest + @EnumSource(value = Language.class) + @DisplayName("문화예술 리스트 조회") + void getCultureAndArtsTest(Language language) { + // given + MemberInfoDto memberInfoDto = getMemberInfoDto(language, TravelType.NONE); + Pageable pageable = PageRequest.of(0, 12); + + List previewDtos = List.of( + ExperienceResponse.PreviewDto.builder() + .title(UUID.randomUUID().toString()) + .addressTag("제주시") + .build(), + ExperienceResponse.PreviewDto.builder() + .title(UUID.randomUUID().toString()) + .addressTag("서귀포시") + .build() + ); + Page previewPage = + new PageImpl<>( + previewDtos, + pageable, + previewDtos.size()); + + doReturn(previewPage).when(experienceRepository) + .findAllExperiencePreviewDtoOrderByPriorityDescAndCreatedAtDesc(language, + ExperienceType.CULTURE_AND_ARTS, List.of(), List.of(), pageable); + doReturn(4.32).when(reviewRepository) + .findTotalRatingAvg(Category.EXPERIENCE, null); + + // when + ExperienceResponse.PreviewPageDto result = experienceService.getExperiencePreviews( + memberInfoDto, ExperienceType.CULTURE_AND_ARTS, List.of(), List.of(), 0, 12); + + // then + assertThat(result.getTotalElements()).isEqualTo(previewDtos.size()); + assertThat(result.getData()).isEqualTo(previewDtos); } ImageFile createImageFile() { @@ -178,17 +215,18 @@ ImageFile createImageFile() { .build(); } - Experience createExperience(ImageFile imageFile) { + Experience createExperience(ImageFile imageFile, ExperienceType experienceType) { return Experience.builder() .priority(0L) .firstImageFile(imageFile) + .experienceType(experienceType) .build(); } - ExperienceTrans createExperienceTrans(Experience experience) { + ExperienceTrans createExperienceTrans(Language language, Experience experience) { return ExperienceTrans.builder() .experience(experience) - .language(Language.KOREAN) + .language(language) .title(UUID.randomUUID().toString()) .content(UUID.randomUUID().toString()) .build(); @@ -205,53 +243,4 @@ private MemberInfoDto getMemberInfoDto(Language language, TravelType travelType) .language(language) .build(); } - - private List getActivityList(Language language, String addressTag, int size) { - List experienceList = new ArrayList<>(); - for (int i = 1; i <= size; i++) { - ImageFile imageFile = ImageFile.builder() - .originUrl("originUrl" + i) - .thumbnailUrl("thumbnailUrl" + i) - .build(); - Experience experience = Experience.builder() - .firstImageFile(imageFile) - .priority(0L) - .experienceType(ExperienceType.ACTIVITY) - .build(); - ExperienceTrans experienceTrans = ExperienceTrans.builder() - .experience(experience) - .title("activity title " + i) - .language(language) - .addressTag(addressTag) - .build(); - - experienceList.add(experience); - } - - return experienceList; - } - - private List getCultureAndArtsList(Language language, String addressTag, int size) { - List cultureAndArtsList = new ArrayList<>(); - for (int i = 1; i <= size; i++) { - ImageFile imageFile = ImageFile.builder() - .originUrl("originUrl" + i) - .thumbnailUrl("thumbnailUrl" + i) - .build(); - Experience experience = Experience.builder() - .firstImageFile(imageFile) - .priority(0L) - .experienceType(ExperienceType.CULTURE_AND_ARTS) - .build(); - ExperienceTrans experienceTrans = ExperienceTrans.builder() - .experience(experience) - .title("culture and arts title " + i) - .language(language) - .addressTag(addressTag) - .build(); - cultureAndArtsList.add(experience); - } - - return cultureAndArtsList; - } } \ No newline at end of file