Commit 4e8ab119 by Patryk Czarnik

orElseThrow dla kodu 404

parent c334179e
...@@ -29,13 +29,9 @@ public class ProductEndpoint { ...@@ -29,13 +29,9 @@ public class ProductEndpoint {
@GetMapping("/{id}") @GetMapping("/{id}")
public Product getOneProduct(@PathVariable("id") Integer id) { public Product getOneProduct(@PathVariable("id") Integer id) {
Optional<Product> product = productRepository.findById(id); return productRepository
if(product.isPresent()) { .findById(id)
return product.get(); .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
} else {
throw 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