pavelnosarev / Capstone3-EasyShop

https://github.com/users/pavelnosarev/projects/2/
1 stars 0 forks source link

Laptop creation bug? #1

Open pavelnosarev opened 1 year ago

pavelnosarev commented 1 year ago

Some users have noticed some products are duplicated. A laptop is listed 3 times, but appears to be the same product with slight differences.

pavelnosarev commented 1 year ago

Laptops are all the same product, but has been edited twice. Check the method.

pavelnosarev commented 1 year ago

Issue Found: create is being used in the update method, need to correct this to prevent more duplicates being made.

Image

pavelnosarev commented 1 year ago

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.