My categories list doesn't empty but when I call fake product API, it return: "message": "bound must be positive"
. Maybe the random made these errors? I don't know why. Help me, please!
@GetMapping("/fake")
public BaseAPI fakeProducts() {
BaseAPI baseAPI = new BaseAPI();
try {
long totalproducts = productService.getTotalProducts();
List<Product> productList = new ArrayList<>();
List<Category> categoryList = new ArrayList<>();
Random random = new Random();
for (long i = totalproducts+1; i <= totalproducts + 10; i++)
{
Product product = new Product();
product.setName("Product" +i);
product.setPrice(prices[random.nextInt(prices.length)]);
product.setMainImage(images[random.nextInt(images.length)]);
product.setSize(sizes[random.nextInt(sizes.length)]);
product.setDisplay(screens[random.nextInt(screens.length)]);
product.setOperatorSystem(os[random.nextInt(os.length)]);
product.setFrontCamera(frontCam[random.nextInt(frontCam.length)]);
product.setBackCamera(backCam[random.nextInt(backCam.length)]);
product.setCategory(categoryList.get(random.nextInt(categoryList.size())));
product.setCreatedDate(new Date());
productList.add(product);
}
productService.addListProducts(productList);
baseAPI.setMessage("success");
}catch (Exception e) {
baseAPI.setMessage(e.getMessage());
}
return baseAPI;
}
Aucun commentaire:
Enregistrer un commentaire