Open pavelnosarev opened 1 year ago
Laptops are all the same product, but has been edited twice. Check the method.
Issue Found: create is being used in the update method, need to correct this to prevent more duplicates being made.
Issue in code is fixed. A success! Made to sure implement a proper method:
@PutMapping("{id}")
// @PreAuthorize("hasRole('ROLE_ADMIN')")
public void updateProduct(@PathVariable int id, @RequestBody Product product)
{
try
{
var existingProduct = productDao.getById(id);
if(existingProduct == null)
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
productDao.update(id, product);
}
catch(Exception ex)
{
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Oops... our bad.");
}
}
Should be good to go now.
Some users have noticed some products are duplicated. A laptop is listed 3 times, but appears to be the same product with slight differences.