diff --git a/src/main/java/com/cona/KUsukKusuk/comment/service/CommentService.java b/src/main/java/com/cona/KUsukKusuk/comment/service/CommentService.java index 202d8d2..321b233 100644 --- a/src/main/java/com/cona/KUsukKusuk/comment/service/CommentService.java +++ b/src/main/java/com/cona/KUsukKusuk/comment/service/CommentService.java @@ -14,6 +14,7 @@ import com.cona.KUsukKusuk.user.dto.BoomarkLikeResponseDto; import com.cona.KUsukKusuk.user.dto.PageInfo; import com.cona.KUsukKusuk.user.service.UserService; +import java.util.Collections; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -116,8 +117,8 @@ public List getPagedComments( int int start = Math.min(pageNumber * pageSize, comments.size()); int end = Math.min((pageNumber + 1) * pageSize, comments.size()); - if (start > end) { - start = end; + if (start >= comments.size()) { + return Collections.emptyList(); // 페이지 범위를 벗어나면 빈 리스트 반환 } PageInfo pageInfo = new PageInfo(); pageInfo.setTotalElements(comments.size()); diff --git a/src/main/java/com/cona/KUsukKusuk/user/service/UserService.java b/src/main/java/com/cona/KUsukKusuk/user/service/UserService.java index 732e0bd..b4c56e0 100644 --- a/src/main/java/com/cona/KUsukKusuk/user/service/UserService.java +++ b/src/main/java/com/cona/KUsukKusuk/user/service/UserService.java @@ -29,6 +29,7 @@ import jakarta.transaction.Transactional; import java.time.Duration; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -290,8 +291,8 @@ public List getBookmarkandLikes(int pageNumber, int page int start = Math.min(pageNumber * pageSize, distinctSpots.size()); int end = Math.min((pageNumber + 1) * pageSize, distinctSpots.size()); - if (start > end) { - start = end; + if (start >= distinctSpots.size()) { + return Collections.emptyList(); } PageInfo pageInfo = new PageInfo(); pageInfo.setTotalElements(distinctSpots.size());