diff --git a/src/main/java/org/brapi/test/BrAPITestServer/repository/primaryEntities/BrAPIRepositoryImpl.java b/src/main/java/org/brapi/test/BrAPITestServer/repository/primaryEntities/BrAPIRepositoryImpl.java index 583a28cf..364cfd8d 100644 --- a/src/main/java/org/brapi/test/BrAPITestServer/repository/primaryEntities/BrAPIRepositoryImpl.java +++ b/src/main/java/org/brapi/test/BrAPITestServer/repository/primaryEntities/BrAPIRepositoryImpl.java @@ -240,10 +240,12 @@ private Long getTotalCount(SearchQueryBuilder searchQuery) { return 0L; } - private void validatePageNumber(Pageable pageReq, Long totalCount) throws InvalidPagingException { - int reqPageNum = pageReq.getPageNumber(); - if (reqPageNum != 0 && reqPageNum > Math.floor(((double) totalCount) / pageReq.getPageSize())) { - // Condition indicates a request was sent where the page requested exceeds the total number of pages. + static void validatePageNumber(Pageable pageReq, Long totalCount) throws InvalidPagingException { + int requestedPage = pageReq.getPageNumber(); + long totalPages = (long) Math.ceil(totalCount / (double) pageReq.getPageSize()); + + // Condition indicates a request was sent where the page requested exceeds the total number of pages. + if (requestedPage > 0 && requestedPage >= totalPages) { // Instruct requester to send the correct request. throw new InvalidPagingException(); }