-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathAccountController.java
More file actions
51 lines (40 loc) · 1.99 KB
/
AccountController.java
File metadata and controls
51 lines (40 loc) · 1.99 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
package io.zipcoder.controller;
import io.zipcoder.domain.Account;
import io.zipcoder.domain.Customer;
import io.zipcoder.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class AccountController {
@Autowired
private AccountService accountService;
public AccountController(AccountService accountService){
this.accountService = accountService;
}
@RequestMapping(value = "/accounts", method = RequestMethod.GET)
public ResponseEntity<?> getAllAccounts(){
return accountService.getAllAccounts();
}
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.GET)
public ResponseEntity<?> getAccountById(@PathVariable("accountId") Long accountId){
return accountService.getAccountById(accountId);
}
@RequestMapping(value = "/customers/{customerId}/accounts", method = RequestMethod.GET)
public ResponseEntity<?> getAccountsForCustomer(@PathVariable("customerId") Long customerId){
return accountService.getAccountsOfCustomer(customerId);
}
@RequestMapping(value = "/customers/{customerId}/accounts", method = RequestMethod.POST)
public ResponseEntity<?> createAccount(@PathVariable ("customerId") Long customerId, @RequestBody Account account){
return accountService.createAccount(customerId, account);
}
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.PUT)
public ResponseEntity<?> updateAccount(@PathVariable("accountId") Long accountId, @RequestBody Account account){
return accountService.updateAccount(account, accountId);
}
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.DELETE)
public ResponseEntity<?> deleteAccount(@PathVariable("accountId") Long accountId){
return accountService.deleteAccount(accountId);
}
}