카드 매입 승인 경로 Spring Boot 3 전환 #6
1 changed files with 38 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package com.acquirex.approval.controller;
|
||||
|
||||
import com.acquirex.approval.dto.ApprovalDto.Request;
|
||||
import com.acquirex.approval.dto.ApprovalDto.Response;
|
||||
import com.acquirex.approval.service.ApprovalService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/approvals")
|
||||
public class ApprovalController {
|
||||
|
||||
private final ApprovalService approvalService;
|
||||
|
||||
public ApprovalController(ApprovalService approvalService) {
|
||||
this.approvalService = approvalService;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Response> submitApproval(@Valid @RequestBody Request request) {
|
||||
Response response = approvalService.processApproval(request);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Response> getApproval(@PathVariable Long id) {
|
||||
var request = approvalService.findById(id);
|
||||
Response response = Response.approved(request.getId(), request.getApprovalCode(), request.getAmount(), request.getCurrency());
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@GetMapping("/stats/pending")
|
||||
public ResponseEntity<Long> getPendingCount() {
|
||||
return ResponseEntity.ok(approvalService.countPendingApprovals());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue