Commit 4e8ab119 by Patryk Czarnik

orElseThrow dla kodu 404

parent c334179e
......@@ -29,13 +29,9 @@ public class ProductEndpoint {
@GetMapping("/{id}")
public Product getOneProduct(@PathVariable("id") Integer id) {
Optional<Product> product = productRepository.findById(id);
if(product.isPresent()) {
return product.get();
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
return productRepository
.findById(id)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment