Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -44,20 +43,15 @@ public BeerDTO saveNewBeer(BeerDTO beer) {

@Override
public Optional<BeerDTO> updateBeerById(UUID beerId, BeerDTO beer) {
AtomicReference<Optional<BeerDTO>> atomicReference = new AtomicReference<>();

beerRepository.findById(beerId).ifPresentOrElse(foundBeer -> {
foundBeer.setBeerName(beer.getBeerName());
foundBeer.setBeerStyle(beer.getBeerStyle());
foundBeer.setUpc(beer.getUpc());
foundBeer.setPrice(beer.getPrice());
atomicReference.set(Optional.of(beerMapper
.beerToBeerDto(beerRepository.save(foundBeer))));
}, () -> {
atomicReference.set(Optional.empty());
});

return atomicReference.get();
return beerRepository.findById(beerId)
.map(foundBeer -> {
foundBeer.setBeerName(beer.getBeerName());
foundBeer.setBeerStyle(beer.getBeerStyle());
foundBeer.setUpc(beer.getUpc());
foundBeer.setPrice(beer.getPrice());
beerRepository.save(foundBeer);
return beerMapper.beerToBeerDto(foundBeer);
});
}

@Override
Expand Down