Skip to content

improvement: avoid null pointers && fix: Method naming case problem #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -76,7 +76,7 @@ public void save(Employee employee) {
* @param employee the employee to be created
* @return the id of the created employee.
*/
public long saveAndReturnId(Employee employee) {
public Long saveAndReturnId(Employee employee) {
String sqlQuery = "insert into employees(first_name, last_name, yearly_income) " +
"values (?, ?, ?)";

Expand All @@ -90,7 +90,11 @@ public long saveAndReturnId(Employee employee) {
return stmt;
}, keyHolder);

return keyHolder.getKey().longValue();
if (keyHolder.getKey() != null) {
return keyHolder.getKey().longValue();
}else {
return null;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ResponseEntity<List<Product>> getAllProducts(){

@GetMapping("product/{id}")
public ResponseEntity<Product> getProductById(@PathVariable("id") int id){
return new ResponseEntity<>(productService.getProductByid(id),HttpStatus.OK);
return new ResponseEntity<>(productService.getProductById(id),HttpStatus.OK);
}

@DeleteMapping("product/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ProductService {

Product addProduct(Product product) throws ProductAlreadyExistsException;
List<Product> getAllProducts();
Product getProductByid(int id);
Product getProductById(int id);
Product deleteProductById(int id);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public List<Product> getAllProducts() {
}

@Override
public Product getProductByid(int id) {
public Product getProductById(int id) {
return productRepository.findById(id).orElse(null);
}

Expand Down