Skip to content

Commit fbb5052

Browse files
Upgraded fetch logic
1 parent 48e0cf1 commit fbb5052

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/main/java/com/encorazone/inventory_manager/service/InventoryServiceImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ public ProductListResponse findByNameAndCategoryAndStockQuantity(String name, St
8585
.and(InventoryProductsFilter.quantityEquals(stockQuantity));
8686

8787
Page<Product> page = productRepository.findAll(spec, pageable);
88+
if (page.getContent().isEmpty()) {
89+
List<Product> ref = productRepository.findAll(spec);
90+
if (!ref.isEmpty()) {
91+
if (ref.size()>= pageable.getPageSize()){
92+
return ProductMapper.toProductListResponse(
93+
ref.subList(
94+
(ref.size() - pageable.getPageSize()),
95+
(ref.size() - 1)),
96+
(int) Math.ceil((double) ref.size()/pageable.getPageSize()));
97+
}
98+
return ProductMapper.toProductListResponse(ref, 1);
99+
}
100+
}
88101
return ProductMapper.toProductListResponse(page.getContent(), page.getTotalPages());
89102
}
90103

0 commit comments

Comments
 (0)