-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCustomerController.java
More file actions
47 lines (37 loc) · 1.72 KB
/
CustomerController.java
File metadata and controls
47 lines (37 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package io.zipcoder.controller;
import io.zipcoder.domain.Account;
import io.zipcoder.domain.Customer;
import io.zipcoder.repository.CustomerRepository;
import io.zipcoder.service.AccountService;
import io.zipcoder.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class CustomerController {
private CustomerService customerService;
@Autowired
public CustomerController(CustomerService customerService){
this.customerService = customerService;
}
@RequestMapping(value = "/customers", method = RequestMethod.GET)
public ResponseEntity<Iterable<Customer>> getAllCustomers(){
return customerService.getAllCustomers();
}
@RequestMapping(value = "/customers/{id}", method = RequestMethod.GET)
public ResponseEntity<Customer> getCustomerById(@PathVariable("id") Long id){
return customerService.getCustomerById(id);
}
@RequestMapping(value = "/accounts/{accountId}/customer", method = RequestMethod.GET)
public ResponseEntity<Customer> getCustomer(@PathVariable("accountId") Long accountId){
return customerService.getCustomerOfAccount(accountId);
}
@RequestMapping(value = "/customers", method = RequestMethod.POST)
public ResponseEntity<?> createCustomer(@RequestBody Customer customer){
return customerService.createCustomer(customer);
}
@RequestMapping(value = "/customers/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> updateCustomer(@PathVariable("id") Long id, @RequestBody Customer customer){
return customerService.updateCustomer(customer, id);
}
}