카드 매입 승인 경로 Spring Boot 3 전환 (ACX-E2E-1785394564819)
This commit is contained in:
parent
ec34b302cf
commit
9536892e5a
1 changed files with 87 additions and 0 deletions
|
|
@ -0,0 +1,87 @@
|
||||||
|
package com.acquirex.approval.controller;
|
||||||
|
|
||||||
|
import com.acquirex.approval.domain.ApprovalStatus;
|
||||||
|
import com.acquirex.approval.dto.ApprovalRequest;
|
||||||
|
import com.acquirex.approval.dto.ApprovalResponse;
|
||||||
|
import com.acquirex.approval.service.CardAcquisitionApprovalService;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST controller for card acquisition approval endpoints.
|
||||||
|
* Migrated to Spring Boot 3 with Jakarta EE 9+ (jakarta.*) annotations.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/approvals")
|
||||||
|
public class CardAcquisitionApprovalController {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CardAcquisitionApprovalController.class);
|
||||||
|
private final CardAcquisitionApprovalService approvalService;
|
||||||
|
|
||||||
|
public CardAcquisitionApprovalController(CardAcquisitionApprovalService approvalService) {
|
||||||
|
this.approvalService = approvalService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a card acquisition approval request.
|
||||||
|
* @param request the approval request with validation
|
||||||
|
* @return the approval response
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public ResponseEntity<ApprovalResponse> processApproval(@Valid @RequestBody ApprovalRequest request) {
|
||||||
|
log.info("Received approval request: {}", request.getRequestId());
|
||||||
|
ApprovalResponse response = approvalService.processApproval(request);
|
||||||
|
return ResponseEntity.status(mapToHttpStatus(response.getStatus())).body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle validation errors from @Valid annotations.
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||||
|
public ResponseEntity<Map<String, Object>> handleValidationErrors(MethodArgumentNotValidException ex) {
|
||||||
|
Map<String, String> fieldErrors = new HashMap<>();
|
||||||
|
ex.getBindingResult().getFieldErrors().forEach(e -> fieldErrors.put(e.getField(), e.getDefaultMessage()));
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("timestamp", LocalDateTime.now());
|
||||||
|
response.put("status", HttpStatus.BAD_REQUEST.value());
|
||||||
|
response.put("error", "Validation Failed");
|
||||||
|
response.put("fieldErrors", fieldErrors);
|
||||||
|
log.warn("Validation error: {}", fieldErrors);
|
||||||
|
return ResponseEntity.badRequest().body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle illegal argument exceptions.
|
||||||
|
*/
|
||||||
|
@ExceptionHandler(IllegalArgumentException.class)
|
||||||
|
public ResponseEntity<Map<String, Object>> handleIllegalArgument(IllegalArgumentException ex) {
|
||||||
|
Map<String, Object> response = new HashMap<>();
|
||||||
|
response.put("timestamp", LocalDateTime.now());
|
||||||
|
response.put("status", HttpStatus.BAD_REQUEST.value());
|
||||||
|
response.put("error", "Bad Request");
|
||||||
|
response.put("message", ex.getMessage());
|
||||||
|
log.warn("Illegal argument: {}", ex.getMessage());
|
||||||
|
return ResponseEntity.badRequest().body(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map approval status to HTTP status.
|
||||||
|
*/
|
||||||
|
private HttpStatus mapToHttpStatus(ApprovalStatus status) {
|
||||||
|
return switch (status) {
|
||||||
|
case APPROVED -> HttpStatus.OK;
|
||||||
|
case REJECTED -> HttpStatus.BAD_REQUEST;
|
||||||
|
case PENDING -> HttpStatus.ACCEPTED;
|
||||||
|
case CANCELLED -> HttpStatus.GONE;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue