-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoanController.java
More file actions
69 lines (61 loc) · 2.7 KB
/
LoanController.java
File metadata and controls
69 lines (61 loc) · 2.7 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
68
69
package com.sbb.flexrate.controller;
import com.sbb.flexrate.dto.*;
import com.sbb.flexrate.exception.DataNotFoundException;
import com.sbb.flexrate.service.LoanService;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequiredArgsConstructor
@RequestMapping("/loan")
public class LoanController {
private final LoanService loanService;
//put method
// @PutMapping("/result/{memberId}")
// public ResponseEntity<?> updateLoan(@PathVariable Long memberId, @RequestBody LoanCreateRequestDto loanDto) {
// try {
// loanService.updateLoan(memberId, loanDto);
// LoanResponseDto responseDto = mapToResponseDto(loanDto); // Map LoanCreateRequestDto to LoanResponseDto
// return ResponseEntity.ok(responseDto);
// } catch (DataNotFoundException e) {
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
// }
// }
@PutMapping("/result/{memberId}")
public ResponseEntity<LoanResponseDto> updateLoan(@PathVariable Long memberId, @RequestBody LoanCreateRequestDto loanDto) {
try {
loanService.updateLoan(memberId, loanDto);
LoanResponseDto responseDto = mapToResponseDto(loanDto); // Map LoanCreateRequestDto to LoanResponseDto
return ResponseEntity.ok(responseDto);
} catch (DataNotFoundException e) {
return ResponseEntity.notFound().build();
}
}
private LoanResponseDto mapToResponseDto(LoanCreateRequestDto loanDto) {
LoanResponseDto responseDto = new LoanResponseDto();
responseDto.setName(loanDto.getName());
responseDto.setInsert_time(loanDto.getInsert_time());
responseDto.setLoan_limit(loanDto.getLoan_limit());
responseDto.setLoan_initial(loanDto.getLoan_initial());
responseDto.setLoan_range_min(loanDto.getLoan_range_min());
responseDto.setLoan_range_max(loanDto.getLoan_range_max());
return responseDto;
}
/* @PostMapping("/request/{memberId}")
public ResponseEntity<?> applyLoan(@PathVariable Long memberId, @RequestBody ApplyRequestDto applyDto){
return
}*/
}
/*
@PostMapping("/request/{memberId}")
public ResponseEntity<?> updateLoan(@PathVariable Long memberId, @RequestBody LoanCreateRequestDto loanDto){
try {
loanService.updateLoan(memberId,loanDto);
return ResponseEntity.ok("Loan 업데이트 성공");
}catch (DataNotFoundException e){
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
}
}*/