- FxService: Cached 레코드에 fetchedAt(Instant) 추가, getCachedAt() 공개 - FxController: GET /api/fx/rate 응답에 updatedAt(ISO 문자열) 포함 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.4 KiB
Java
41 lines
1.4 KiB
Java
package com.sb.web.account.controller;
|
|
|
|
import com.sb.web.account.service.FxService;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.time.Instant;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 환율 조회 API. 외화 결제 입력 시 통화→원화 환율 자동 채움용.
|
|
* GET /api/fx/rate?from=USD&to=KRW → { from, to, rate }
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/fx")
|
|
public class FxController {
|
|
|
|
private final FxService fxService;
|
|
|
|
public FxController(FxService fxService) {
|
|
this.fxService = fxService;
|
|
}
|
|
|
|
@GetMapping("/rate")
|
|
public Map<String, Object> rate(@RequestParam String from,
|
|
@RequestParam(defaultValue = "KRW") String to) {
|
|
BigDecimal rate = fxService.getRate(from, to);
|
|
Instant updatedAt = fxService.getCachedAt(from);
|
|
Map<String, Object> res = new HashMap<>();
|
|
res.put("from", from == null ? null : from.toUpperCase());
|
|
res.put("to", to == null ? null : to.toUpperCase());
|
|
res.put("rate", rate); // 조회 실패 시 null
|
|
res.put("updatedAt", updatedAt != null ? updatedAt.toString() : null);
|
|
return res;
|
|
}
|
|
}
|