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

[#534] fix: 이색체험 찜리스트 수정 #535

Merged
merged 1 commit into from
Jan 7, 2025
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.jeju.nanaland.domain.favorite.controller;

import static com.jeju.nanaland.domain.common.data.Category.EXPERIENCE;
import static com.jeju.nanaland.domain.common.data.Category.FESTIVAL;
import static com.jeju.nanaland.domain.common.data.Category.MARKET;
import static com.jeju.nanaland.domain.common.data.Category.NANA;
import static com.jeju.nanaland.domain.common.data.Category.NATURE;
import static com.jeju.nanaland.domain.common.data.Category.RESTAURANT;
import static com.jeju.nanaland.global.exception.SuccessCode.POST_LIKE_TOGGLE_SUCCESS;

import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.favorite.dto.FavoriteRequest.LikeToggleDto;
import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse;
import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse.StatusDto;
Expand Down Expand Up @@ -66,11 +66,12 @@ public BaseResponse<FavoriteResponse.PreviewPageDto> getAllFavorites(
@GetMapping("/experience/list")
public BaseResponse<FavoriteResponse.PreviewPageDto> getExperienceFavorites(
@AuthMember MemberInfoDto memberInfoDto,
@RequestParam ExperienceType experienceType,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "12") int size) {

FavoriteResponse.PreviewPageDto favoritePreviewPageDto =
favoriteService.getAllCategoryFavorites(memberInfoDto, EXPERIENCE, page, size);
favoriteService.getExperienceFavorites(memberInfoDto, experienceType, page, size);
return BaseResponse.success(SuccessCode.GET_FAVORITE_LIST_SUCCESS, favoritePreviewPageDto);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jeju.nanaland.domain.favorite.repository;

import com.jeju.nanaland.domain.common.data.Category;
import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.favorite.entity.Favorite;
import com.jeju.nanaland.domain.member.entity.Member;
import java.util.List;
Expand All @@ -14,5 +15,8 @@ public interface FavoriteRepositoryCustom {
Page<Favorite> findAllFavoritesOrderByModifiedAtDesc(Member member, Category category,
Pageable pageable);

Page<Favorite> findAllExperienceFavoritesOrderByModifiedAtDesc(Member member,
ExperienceType experienceType, Pageable pageable);

List<Favorite> findAllFavoriteToSendNotification();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.jeju.nanaland.domain.favorite.repository;

import static com.jeju.nanaland.domain.experience.entity.QExperience.experience;
import static com.jeju.nanaland.domain.favorite.entity.QFavorite.favorite;

import com.jeju.nanaland.domain.common.data.Category;
import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.favorite.entity.Favorite;
import com.jeju.nanaland.domain.member.entity.Member;
import com.querydsl.core.types.dsl.BooleanExpression;
Expand Down Expand Up @@ -73,6 +75,42 @@ public Page<Favorite> findAllFavoritesOrderByModifiedAtDesc(Member member, Categ
return PageableExecutionUtils.getPage(resultDto, pageable, countQuery::fetchOne);
}

@Override
public Page<Favorite> findAllExperienceFavoritesOrderByModifiedAtDesc(Member member,
ExperienceType experienceType, Pageable pageable) {
Category category = Category.EXPERIENCE;

List<Favorite> resultDto = queryFactory
.select(favorite)
.from(favorite)
.innerJoin(experience)
.on(favorite.post.id.eq(experience.id)
.and(experience.experienceType.eq(experienceType)))
.where(
favorite.member.eq(member),
favorite.category.eq(category),
favorite.status.eq("ACTIVE")
)
.orderBy(favorite.modifiedAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

JPAQuery<Long> countQuery = queryFactory
.select(favorite.count())
.from(favorite)
.innerJoin(experience)
.on(favorite.post.id.eq(experience.id)
.and(experience.experienceType.eq(experienceType)))
.where(
favorite.member.eq(member),
favorite.category.eq(category),
favorite.status.eq("ACTIVE")
);

return PageableExecutionUtils.getPage(resultDto, pageable, countQuery::fetchOne);
}

@Override
public List<Favorite> findAllFavoriteToSendNotification() {
LocalDateTime now = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jeju.nanaland.domain.common.data.Language;
import com.jeju.nanaland.domain.common.dto.PostPreviewDto;
import com.jeju.nanaland.domain.common.service.PostService;
import com.jeju.nanaland.domain.experience.entity.enums.ExperienceType;
import com.jeju.nanaland.domain.favorite.dto.FavoriteRequest;
import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse;
import com.jeju.nanaland.domain.favorite.dto.FavoriteResponse.PreviewDto;
Expand Down Expand Up @@ -120,6 +121,52 @@ public FavoriteResponse.PreviewPageDto getAllCategoryFavorites(MemberInfoDto mem
.build();
}

/**
* 이색체험 찜리스트 조회
*
* @param memberInfoDto 회원 정보
* @param page 페이지
* @param size 페이지 크기
* @return FavoriteResponse.PreviewPageDto
*/
@Transactional(readOnly = true)
public FavoriteResponse.PreviewPageDto getExperienceFavorites(MemberInfoDto memberInfoDto,
ExperienceType experienceType, int page, int size) {

Member member = memberInfoDto.getMember();
Category category = Category.EXPERIENCE;
Language language = memberInfoDto.getLanguage();
Pageable pageable = PageRequest.of(page, size);

// favorite 테이블에서 해당 유저의 이색체험(액티비티, 문화예술) 찜리스트 페이지 조회
Page<Favorite> favoritePage =
favoriteRepository.findAllExperienceFavoritesOrderByModifiedAtDesc(member, experienceType
, pageable);

// 각 게시물 조회 쿼리 비동기 요청
List<CompletableFuture<FavoriteResponse.PreviewDto>> favoritePreviewFutures = favoritePage.get()
.map(favorite -> CompletableFuture.supplyAsync(() -> {
Long postId = favorite.getPost().getId();
PostPreviewDto postPreviewDto = postService.getPostPreviewDto(postId, category, language);
return new FavoriteResponse.PreviewDto(postPreviewDto);
}))
.toList();

// 모든 비동기 작업이 완료될 때까지 기다린 후 각 결과를 수집
List<FavoriteResponse.PreviewDto> favoritePreviewDtos = CompletableFuture.allOf(
favoritePreviewFutures.toArray(new CompletableFuture[0])
).thenApply(v ->
favoritePreviewFutures.stream()
.map(CompletableFuture::join) // 순서대로 결과 가져오기
.collect(Collectors.toList())
).join(); // 최종 결과 리스트

return FavoriteResponse.PreviewPageDto.builder()
.totalElements(favoritePage.getTotalElements())
.data(favoritePreviewDtos)
.build();
}

/**
* 찜 등록, 취소 토글
*
Expand Down
Loading