-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCustomerController.java
More file actions
67 lines (52 loc) · 2.39 KB
/
CustomerController.java
File metadata and controls
67 lines (52 loc) · 2.39 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package io.zipcoder.controller;
import com.sun.deploy.net.HttpResponse;
import io.zipcoder.domain.Account;
import io.zipcoder.domain.Customer;
import io.zipcoder.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class CustomerController {
CustomerService service;
@Autowired
public CustomerController(CustomerService service){
this.service = service;
}
@RequestMapping(value = "/customers/{id}/accounts", method = RequestMethod.GET)
public ResponseEntity<?> getAllAcctsForCust(@PathVariable Long id) {
return new ResponseEntity<>(service.getAllAccountsForCust(id), HttpStatus.OK);
}
@RequestMapping(value = "/customers/{id}/accounts", method = RequestMethod.POST)
public ResponseEntity<?> createAccount(@PathVariable Long id, @RequestBody Account account){
service.createAccount(account);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@RequestMapping(value = "/customers", method = RequestMethod.GET)
public ResponseEntity<?> getAllCustomers(){
return new ResponseEntity<>(service.getAllCustomers(), HttpStatus.OK);
}
@RequestMapping(value = "/customers/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getSpecificCusomer(@PathVariable Long id){
return new ResponseEntity<>(service.getCustomerById(id), HttpStatus.OK);
}
@RequestMapping(value = "/customers", method = RequestMethod.POST)
public ResponseEntity<?> createACustomer(@RequestBody Customer customer){
service.addCustomer(customer);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@RequestMapping(value = "/customer/{id}", method = RequestMethod.PUT)
public ResponseEntity<?> updateCustomer(@PathVariable Long id, @RequestBody Customer customer){
if(service.updateCustomer(id,customer)){
return new ResponseEntity<>(HttpStatus.OK);
}
else{
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@RequestMapping(value = "/customer/{id}/bills", method = RequestMethod.GET)
public ResponseEntity<?> getAllBillsForCust(@PathVariable Long id){
return new ResponseEntity<>(service.getAllBillsForCustomer(id), HttpStatus.OK);
}
}