Skip to content

Commit a7f639a

Browse files
committed
Implement get customer by id method in CustomerService
1 parent f426b30 commit a7f639a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/hsbc/simpleapi/service/CustomerService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.hsbc.simpleapi.service;
22

3+
import javax.persistence.EntityNotFoundException;
4+
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.stereotype.Service;
57

68
import com.hsbc.simpleapi.model.Customer;
79
import com.hsbc.simpleapi.dao.CustomerRepository;
810

9-
import javax.persistence.EntityNotFoundException;
10-
1111
@Service
1212
public class CustomerService {
1313

@@ -21,4 +21,9 @@ public CustomerService(CustomerRepository customerRepository) {
2121
public Customer insert(Customer customer) {
2222
return customerRepository.save(customer);
2323
}
24+
25+
public Customer getCustomerBy(long id) {
26+
return customerRepository.findById(id)
27+
.orElseThrow(() -> new EntityNotFoundException("Customer under given id does not exist."));
28+
}
2429
}

0 commit comments

Comments
 (0)