diff --git a/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java b/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java index ba5b9f4..0b14b53 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/controller/MarketController.java @@ -35,7 +35,7 @@ public ResponseEntity> getMarket(@PathVariable // size가 null로 들어올 시 기본 값을 지정해주기 위해 integer로 값을 받아온다. @Operation(summary = "전체 매장 조회", - description = "처음 요청 시, pageSize만 필요합니다. 기본값은 5입니다.
" + + description = "처음 요청 시, pageSize만 필요합니다. 기본값은 10입니다.
" + "카테고리 별 매장을 조회하시려면 category도 필요합니다.
" + "최신순으로 보여줍니다.") @GetMapping @@ -44,7 +44,7 @@ public ResponseEntity>> getMarket( @Parameter(description = "페이지의 마지막 marketId") @RequestParam(required = false, name = "lastPageIndex") Long marketId, @RequestParam(required = false, name = "category") String major, - @RequestParam(defaultValue = "5", name = "pageSize") Integer size) + @RequestParam(defaultValue = "10", name = "pageSize") Integer size) { return ResponseEntity .ok(CommonResponse.from(MARKET_FOUND.getMessage() @@ -53,7 +53,7 @@ public ResponseEntity>> getMarket( @Operation(summary = "자신이 찜한 매장 조회", description = "자신이 찜한 매장 정보 리스트를 반환합니다.
" + - "처음 요청 시엔 pageSize만 필요합니다.기본값은 5입니다.
" + + "처음 요청 시엔 pageSize만 필요합니다.기본값은 10입니다.
" + "JWT 구현 전 까지는 memberId를 추가해야합니다.
" + "최신 찜 순으로 보여줍니다.") @GetMapping("/my-favorite") @@ -61,7 +61,7 @@ public ResponseEntity>> getMem @RequestParam Long memberId, @Parameter(description = "페이지의 마지막 favoriteModifiedAt (e.g. 2024-11-25 11:19:26.378948 )") @RequestParam(required = false, name = "lastModifiedAt") LocalDateTime lastModifiedAt, - @RequestParam(defaultValue = "5", name = "pageSize") Integer size) { + @RequestParam(defaultValue = "10", name = "pageSize") Integer size) { return ResponseEntity .ok(CommonResponse.from(MARKET_FOUND.getMessage() ,marketService.getMyFavoriteMarketPage(memberId,lastModifiedAt,size))); @@ -69,25 +69,27 @@ public ResponseEntity>> getMem @Operation(summary = "찜 수가 가장 많은 매장 더보기 조회", description = "사용자들이 가장 많이 찜한 매장 정보 리스트를 반환합니다.
" + - "처음 요청 시엔 pageSize만 필요합니다. 기본값은 5입니다.
" + + "처음 요청 시엔 pageSize만 필요합니다. 기본값은 10입니다.
" + "찜 수가 가장 많은 순으로 보여줍니다.") @GetMapping("/favorite") public ResponseEntity>> getTopFavoriteMarketList( @RequestParam Long memberId, + @Parameter(description = "페이지의 마지막 marketId") + @RequestParam(required = false, name = "lastMarketId") Long marketId, @Parameter(description = "페이지의 마지막 favoriteCount") @RequestParam(required = false, name = "lastFavoriteCount") Long count, - @RequestParam(defaultValue = "5", name = "pageSize") Integer size) { + @RequestParam(defaultValue = "10", name = "pageSize") Integer size) { return ResponseEntity .ok(CommonResponse.from(MARKET_FOUND.getMessage() - ,marketService.getFavoriteMarketPage(memberId,count,size))); + ,marketService.getFavoriteMarketPage(memberId,marketId,count,size))); } @Operation(summary = "찜 수가 가장 많은 매장 TOP 조회", description = "사용자들이 가장 많이 찜한 매장 Top을 반환합니다.
" + - "size의 기본값은 5입니다.") + "size의 기본값은 10입니다.") @GetMapping("/top-favorite") public ResponseEntity>> getTopFavoriteMarketList( - @RequestParam(defaultValue = "5", name = "size") Integer size) { + @RequestParam(defaultValue = "10", name = "size") Integer size) { return ResponseEntity .ok(CommonResponse.from(MARKET_FOUND.getMessage() ,marketService.getTopFavoriteMarkets(size))); diff --git a/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustom.java b/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustom.java index e6492bb..e68146f 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustom.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustom.java @@ -14,7 +14,7 @@ public interface MarketRepositoryCustom { public List findMyFavoriteMarketList(Long memberId, LocalDateTime lastModifiedAt, Integer size); - public List findFavoriteMarketList(Long memberId, Long count, Integer size); + public List findFavoriteMarketList(Long memberId,Long marketId, Long count, Integer size); public List findTopFavoriteMarkets(Integer size); diff --git a/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustomImpl.java b/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustomImpl.java index dcccf47..ad82a3b 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustomImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/repository/MarketRepositoryCustomImpl.java @@ -1,6 +1,7 @@ package com.appcenter.marketplace.domain.market.repository; import com.appcenter.marketplace.domain.coupon.QCoupon; +import com.appcenter.marketplace.domain.favorite.QFavorite; import com.appcenter.marketplace.domain.image.dto.res.QImageRes; import com.appcenter.marketplace.domain.market.dto.res.*; import com.querydsl.core.BooleanBuilder; @@ -36,7 +37,7 @@ public List findMarketDetailList(Long marketId) { // market과 image를 조인 하여 매장 정보와 순서에 오름차순인 이미지 리스트를 dto에 매핑한다. return jpaQueryFactory .from(market) - .innerJoin(image.market,market) + .innerJoin(image).on(image.market.eq(market)) .where(market.id.eq(marketId)) // 매장 ID로 필터링 .orderBy(image.sequence.asc()) // transfrom을 통해 쿼리 결과를 원하는 형태로 변환한다. @@ -67,8 +68,9 @@ public List findMarketList(Long memberId, Long marketId, Integer size market.thumbnail, favorite.id.isNotNull())) .from(market) - .leftJoin(favorite.market,market).on(favorite.member.id.eq(memberId) - .and(favorite.isDeleted.eq(false))) + .leftJoin(favorite).on(market.eq(favorite.market) + .and(favorite.member.id.eq(memberId) + .and(favorite.isDeleted.eq(false)))) .innerJoin(market.local,local) .innerJoin(local.metro,metro) .where(ltMarketId(marketId)) @@ -89,8 +91,9 @@ public List findMarketListByCategory(Long memberId, Long marketId, In market.thumbnail, favorite.id.isNotNull())) .from(market) - .leftJoin(favorite.market,market).on(favorite.member.id.eq(memberId) - .and(favorite.isDeleted.eq(false))) + .leftJoin(favorite).on(market.eq(favorite.market) + .and(favorite.member.id.eq(memberId) + .and(favorite.isDeleted.eq(false)))) .innerJoin(market.category,category) .innerJoin(market.local,local) .innerJoin(local.metro,metro) @@ -113,8 +116,9 @@ public List findMyFavoriteMarketList(Long memberId, LocalDa favorite.id.isNotNull(), favorite.modifiedAt)) .from(market) - .innerJoin(favorite.market,market).on(favorite.member.id.eq(memberId) - .and(favorite.isDeleted.eq(false))) + .innerJoin(favorite).on(market.eq(favorite.market) + .and(favorite.member.id.eq(memberId) + .and(favorite.isDeleted.eq(false)))) .innerJoin(market.local,local) .innerJoin(local.metro,metro) .where(ltFavoriteModifiedAt(lastModifiedAt)) // 회원 자신이 동시간대에 찜할 수 없으므로 lt이다. @@ -125,7 +129,9 @@ public List findMyFavoriteMarketList(Long memberId, LocalDa // 찜 수가 가장 많은 매장 페이징 조회 @Override - public List findFavoriteMarketList(Long memberId, Long count, Integer size) { + public List findFavoriteMarketList(Long memberId,Long marketId, Long count, Integer size) { + QFavorite favoriteMember = new QFavorite("favoriteMember"); // 해당 사용자의 각 매장의 찜 여부 확인을 위한 별칭 생성 + return jpaQueryFactory .select(new QFavoriteMarketRes( market.id, @@ -133,17 +139,21 @@ public List findFavoriteMarketList(Long memberId, Long count, market.description, metro.name.concat(" ").concat(local.name), market.thumbnail, - favorite.id.isNotNull(), - favorite.member.id.count())) + favoriteMember.id.isNotNull(), + favorite.id.count())) .from(market) + // 모든 사용자 기준 찜 데이터 JOIN .leftJoin(favorite).on(market.eq(favorite.market) - .and(favorite.member.id.eq(memberId) - .and(favorite.isDeleted.eq(false)))) + .and(favorite.isDeleted.eq(false))) + // 특정 사용자의 찜 여부 확인을 위한 JOIN + .leftJoin(favoriteMember).on(market.eq(favoriteMember.market) + .and(favoriteMember.member.id.eq(memberId) + .and(favoriteMember.isDeleted.eq(false)))) .innerJoin(local).on(market.local.eq(local)) .innerJoin(metro).on(local.metro.eq(metro)) - .where(loeFavoriteCount(count)) // 삭제되지 않은 찜만 필터링 - .groupBy(market.id, market.name, market.description, metro.name, local.name, market.thumbnail,favorite.id) - .orderBy(favorite.member.id.count().desc(),market.id.desc()) // 찜 수가 많은 순으로 정렬 + .groupBy(market.id, market.name, market.description, metro.name, local.name, market.thumbnail,favoriteMember.id) + .having(loeFavoriteCountAndLtMarketId(count,marketId)) + .orderBy(favorite.id.count().desc(),market.id.desc()) // 찜 수가 많은 순으로 정렬 .limit(size+1) // 반환할 리스트 크기 제한 .fetch(); // 결과 반환 } @@ -157,7 +167,8 @@ public List findTopFavoriteMarkets(Integer size) { market.name, market.thumbnail)) .from(market) - .leftJoin(favorite.market,market).on(favorite.isDeleted.eq(false)) + .leftJoin(favorite).on(market.eq(favorite.market) + .and(favorite.isDeleted.eq(false))) .groupBy(market.id, market.name, market.thumbnail) .orderBy(favorite.id.count().desc()) // 찜 수가 많은 순으로 정렬 .fetch(); @@ -278,10 +289,16 @@ private BooleanBuilder ltMarketId(Long marketId){ } // loe= less or equal = <=(~보다 작거나 같은) - private BooleanBuilder loeFavoriteCount(Long count){ + private BooleanBuilder loeFavoriteCountAndLtMarketId(Long count,Long marketId){ BooleanBuilder builder = new BooleanBuilder(); - if (count != null) { - builder.and(favorite.member.id.count().loe(count)); + if (count != null && marketId!=null) { + builder.and(favorite.id.count().loe(count)); + + // A or B 여서 둘중 하나의 조건만 만족하면 true + // count보다 작으면. A가 true이기 때문에 B는 실행되지않음 + // A가 false이면 market.id 필터링한 행들만 true + // 따라서 favorite.id.count()가 count와 같을 때만 market.id 필터링 + builder.and(favorite.id.count().lt(count).or(market.id.lt(marketId))); } return builder; diff --git a/src/main/java/com/appcenter/marketplace/domain/market/service/MarketService.java b/src/main/java/com/appcenter/marketplace/domain/market/service/MarketService.java index 0c1be96..1e347e0 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/service/MarketService.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/service/MarketService.java @@ -13,7 +13,7 @@ public interface MarketService { MarketPageRes getMyFavoriteMarketPage(Long memberId, LocalDateTime lastModifiedAt, Integer size); - MarketPageRes getFavoriteMarketPage(Long memberId, Long count, Integer size); + MarketPageRes getFavoriteMarketPage(Long memberId, Long marketId, Long count, Integer size); List getTopFavoriteMarkets(Integer size); List getTopLatestCoupons(Integer size); diff --git a/src/main/java/com/appcenter/marketplace/domain/market/service/impl/MarketServiceImpl.java b/src/main/java/com/appcenter/marketplace/domain/market/service/impl/MarketServiceImpl.java index c90b30c..3b47644 100644 --- a/src/main/java/com/appcenter/marketplace/domain/market/service/impl/MarketServiceImpl.java +++ b/src/main/java/com/appcenter/marketplace/domain/market/service/impl/MarketServiceImpl.java @@ -58,8 +58,8 @@ public MarketPageRes getMyFavoriteMarketPage(Long memberId, // 찜 수가 가장 많은 매장 더보기 조회 @Override - public MarketPageRes getFavoriteMarketPage(Long memberId, Long count, Integer size) { - List favoriteMarketResList = marketRepository.findFavoriteMarketList(memberId, count, size); + public MarketPageRes getFavoriteMarketPage(Long memberId, Long marketId, Long count, Integer size) { + List favoriteMarketResList = marketRepository.findFavoriteMarketList(memberId, marketId, count, size); return checkNextPageAndReturn(favoriteMarketResList, size); }