File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed
src/main/java/com/hsbc/simpleapi/controller Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change 11package com .hsbc .simpleapi .controller ;
22
3+ import javax .persistence .EntityNotFoundException ;
4+
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+
7+ import org .springframework .http .HttpStatus ;
8+ import org .springframework .http .ResponseEntity ;
9+
10+ import org .springframework .web .bind .annotation .GetMapping ;
11+ import org .springframework .web .bind .annotation .PathVariable ;
12+ import org .springframework .web .bind .annotation .RequestMapping ;
13+ import org .springframework .web .bind .annotation .RestController ;
14+ import org .springframework .web .server .ResponseStatusException ;
15+
16+ import com .hsbc .simpleapi .model .Customer ;
17+ import com .hsbc .simpleapi .service .CustomerService ;
18+
19+ @ RestController
20+ @ RequestMapping ("/api/customer" )
321public class CustomerController {
4- }
22+
23+ private CustomerService customerService ;
24+
25+ @ Autowired
26+ public CustomerController (CustomerService customerService ) {
27+ this .customerService = customerService ;
28+ }
29+
30+ @ GetMapping ("{id}" )
31+ public ResponseEntity <Customer > getCustomerById (@ PathVariable ("id" ) long id ) {
32+ try {
33+ return new ResponseEntity <>(customerService .getCustomerBy (id ), HttpStatus .OK );
34+ } catch (EntityNotFoundException e ) {
35+ throw new ResponseStatusException (HttpStatus .NOT_FOUND , e .getMessage ());
36+ }
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments