PrepZone Logo
PrepZone
Back to AI Coding

AI Coding · Medium

Two admins editing the same product sometimes overwrite each other. The assistant's update code is below. Fix it.

AI CodingCode ReviewStaff
java
@PutMapping("/products/{id}")
@Transactional
public Product update(@PathVariable long id, @RequestBody ProductDto dto) {
    Product p = repo.findById(id).orElseThrow();
    p.setName(dto.name());
    p.setPrice(dto.price());
    p.setStock(dto.stock());
    return repo.save(p);
}