-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathWithdrawalController.java
More file actions
40 lines (33 loc) · 1.57 KB
/
WithdrawalController.java
File metadata and controls
40 lines (33 loc) · 1.57 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
package io.zipcoder.controller;
import io.zipcoder.domain.Withdrawal;
import io.zipcoder.service.WithdrawalService;
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 WithdrawalController {
private WithdrawalService withdrawalService;
@Autowired
WithdrawalController(WithdrawalService withdrawalService){
this.withdrawalService = withdrawalService;
}
@RequestMapping(value = "/withdrawals/{withdrawalId}", method = RequestMethod.GET)
public ResponseEntity getWithdrawalById(@PathVariable long withdrawalId){
return new ResponseEntity(this.withdrawalService.getWithdrawalById(withdrawalId), HttpStatus.OK);
}
@RequestMapping(value = "/withdrawals/{withdrawalid}", method = RequestMethod.PUT)
public ResponseEntity updateWithdrawal(@PathVariable long withdrawalId, @RequestBody Withdrawal withdrawalToUpdate){
boolean wasUpdated = this.withdrawalService.updateWithdrawal(withdrawalToUpdate);
if (wasUpdated) {
return new ResponseEntity(HttpStatus.OK);
} else {
return new ResponseEntity(HttpStatus.NOT_FOUND);
}
}
@RequestMapping(value = "/withdrawals/{withdrawalId}", method = RequestMethod.DELETE)
public ResponseEntity deleteWithdrawalById(@PathVariable long withdrawalId){
this.withdrawalService.deleteWithdrawalById(withdrawalId);
return new ResponseEntity(HttpStatus.OK);
}
}