Skip to content

Commit

Permalink
[Feat] 페이지 조회 시 데이터 건너뜀 방지 조건 추가 - #70
Browse files Browse the repository at this point in the history
  • Loading branch information
kangwook1 committed Nov 29, 2024
1 parent 9a470d4 commit 7d268f7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ public ResponseEntity<CommonResponse<MarketPageRes<MyFavoriteMarketRes>>> getMem
@GetMapping("/favorite")
public ResponseEntity<CommonResponse<MarketPageRes<FavoriteMarketRes>>> 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 = "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 조회",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface MarketRepositoryCustom {

public List<MyFavoriteMarketRes> findMyFavoriteMarketList(Long memberId, LocalDateTime lastModifiedAt, Integer size);

public List<FavoriteMarketRes> findFavoriteMarketList(Long memberId, Long count, Integer size);
public List<FavoriteMarketRes> findFavoriteMarketList(Long memberId,Long marketId, Long count, Integer size);

public List<TopFavoriteMarketRes> findTopFavoriteMarkets(Integer size);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public List<MyFavoriteMarketRes> findMyFavoriteMarketList(Long memberId, LocalDa

// 찜 수가 가장 많은 매장 페이징 조회
@Override
public List<FavoriteMarketRes> findFavoriteMarketList(Long memberId, Long count, Integer size) {
public List<FavoriteMarketRes> findFavoriteMarketList(Long memberId,Long marketId, Long count, Integer size) {
QFavorite favoriteMember = new QFavorite("favoriteMember"); // 해당 사용자의 각 매장의 찜 여부 확인을 위한 별칭 생성

return jpaQueryFactory
Expand All @@ -151,8 +151,8 @@ public List<FavoriteMarketRes> findFavoriteMarketList(Long memberId, Long count,
.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,favoriteMember.id)
.having(loeFavoriteCountAndLtMarketId(count,marketId))
.orderBy(favorite.id.count().desc(),market.id.desc()) // 찜 수가 많은 순으로 정렬
.limit(size+1) // 반환할 리스트 크기 제한
.fetch(); // 결과 반환
Expand Down Expand Up @@ -289,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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface MarketService {

MarketPageRes<MyFavoriteMarketRes> getMyFavoriteMarketPage(Long memberId, LocalDateTime lastModifiedAt, Integer size);

MarketPageRes<FavoriteMarketRes> getFavoriteMarketPage(Long memberId, Long count, Integer size);
MarketPageRes<FavoriteMarketRes> getFavoriteMarketPage(Long memberId, Long marketId, Long count, Integer size);
List<TopFavoriteMarketRes> getTopFavoriteMarkets(Integer size);

List<TopLatestCouponRes> getTopLatestCoupons(Integer size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public MarketPageRes<MyFavoriteMarketRes> getMyFavoriteMarketPage(Long memberId,

// 찜 수가 가장 많은 매장 더보기 조회
@Override
public MarketPageRes<FavoriteMarketRes> getFavoriteMarketPage(Long memberId, Long count, Integer size) {
List<FavoriteMarketRes> favoriteMarketResList = marketRepository.findFavoriteMarketList(memberId, count, size);
public MarketPageRes<FavoriteMarketRes> getFavoriteMarketPage(Long memberId, Long marketId, Long count, Integer size) {
List<FavoriteMarketRes> favoriteMarketResList = marketRepository.findFavoriteMarketList(memberId, marketId, count, size);

return checkNextPageAndReturn(favoriteMarketResList, size);
}
Expand Down

0 comments on commit 7d268f7

Please sign in to comment.