class CandyService {
private SupplyRepository supplyRepository;
void updateBarcode(String id, String newBarcode) {
var supply = supplyRepository.findById(id).orElseThrow();
supply.setBarcode(newBarcode);
supplyRepository.save(supply);
}
}
class CandyService {
private SupplyRepository supplyRepository;
void updateBarcode(String id, String newBarcode) {
var supply = supplyRepository.findById(id)
.orElseThrow(() -> new NoSuchElementException("Unknown " + id));
supply.setBarcode(newBarcode);
supplyRepository.save(supply);
}
}