Commit: 690c1f6

Commit Details

SHA690c1f6ce426c62c29e87ac132dda0f8125192ff
Tree5a67fd55b56735ab4e469c7d06c1c73c4c2b4c20
Author<f69e50@finnacloud.com> 1766368110 +0300
Committer<f69e50@finnacloud.com> 1766368110 +0300
Message
initialize backend structure with controllers, DTOs, and configuration files
GPG Signature
-----BEGIN PGP SIGNATURE-----

iQJSBAABCAA8FiEEWJb139mJI+vZ81KkoAIVSUsXI0oFAmlIo24eHHNvcGhpYS5l
cmFzbGFuQGZpbm5hY2xvdWQuY29tAAoJEKACFUlLFyNKwXYP/RvWx8mxXoZbKEVA
wQFC9UnzcoL/lElB5QMr9opKzRv4uGgFkKMDhbSnqE6NoET5H5VanOFQ9u5a4Khi
9PBTLIEBjbEqA1trC+aTDk3EplVtQYYbSn19CdMSCW7FXJNSg0IiyWKA44iH8Ts0
Xcxh59m6WcwvRDhxQDy6hCXqUa9ISNNk75KRnJS/qRGIEy94DwUYxVfCJpAfzyVu
VmdinE6kZM2GDj8MBTPQTzi6hMf/e9CcAg51tf4oNtd9tnW8QKpTsPsFy434VUDh
Vxtv/oAJ5tuTIprs2BSnyZ6Kb8RDwDdmQyuKjZMUIwZTH/TCE85SZFf5sa5tpYOH
2KekT52ffZgKw/DUtpNosW6qeHgCJlSvwY7BW7M90X5xJuahrKS04lEDBO04cIRn
bg0ayPFTp7Idhl1OuTRhWS6e344g44mJ/9sZK1sXd/0U8OKBbytk35AnCIPCEdSX
8vgjqBR9Wt3A/Kel5j2VcUFDhrAR72a9lJiQHNBicvcVu9Nd41vDnEwUDdNQv6Uc
6omEz3pkVkq+89/eW1KQM8LvrIuGQ/wIUgykvCNSCQ5oba2fjtAXzI+SmxpeCWOz
jTKZOEJyhIQE7uvaUj6/0D2JwlxbMG27fcUN7N3aKv6mSVP7hYnHaUbRLQ+f8/xU
VfU776FkUXS+4CfSooHtu+ioul9O
=ZuqE
-----END PGP SIGNATURE-----

✓ Verified

File: src/main/java/com/paymentlink/controller/api/CurrencyApiController.java

1 package com.paymentlink.controller.api;
2
3 import com.paymentlink.model.entity.ExchangeRate;
4 import com.paymentlink.service.CurrencyService;
5 import org.springframework.http.HttpStatus;
6 import org.springframework.http.ResponseEntity;
7 import org.springframework.web.bind.annotation.*;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12 import java.util.Set;
13
14 @RestController
15 @RequestMapping("/api/currency")
16 public class CurrencyApiController {
17
18 private final CurrencyService currencyService;
19
20 public CurrencyApiController(CurrencyService currencyService) {
21 this.currencyService = currencyService;
22 }
23
24 /**
25 * GET /api/currency/rates - Get all current exchange rates
26 */
27 @GetMapping("/rates")
28 public ResponseEntity<Map<String, Object>> getExchangeRates() {
29 try {
30 List<ExchangeRate> rates = currencyService.getAllRates();
31
32 Map<String, Object> response = new HashMap<>();
33 response.put("success", true);
34 response.put("rates", rates);
35 response.put("total", rates.size());
36
37 return ResponseEntity.ok(response);
38 } catch (Exception e) {
39 Map<String, Object> error = new HashMap<>();
40 error.put("success", false);
41 error.put("error", e.getMessage());
42 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
43 }
44 }
45
46 /**
47 * GET /api/currency/convert - Convert an amount between currencies
48 */
49 @GetMapping("/convert")
50 public ResponseEntity<Map<String, Object>> convertCurrency(
51 @RequestParam Long amount,
52 @RequestParam String from,
53 @RequestParam String to) {
54
55 try {
56 Long converted = currencyService.convertPrice(amount, from, to);
57 Double rate = currencyService.getRate(from, to);
58
59 Map<String, Object> response = new HashMap<>();
60 response.put("success", true);
61 response.put("fromAmount", amount);
62 response.put("fromCurrency", from);
63 response.put("toAmount", converted);
64 response.put("toCurrency", to);
65 response.put("rate", rate);
66
67 return ResponseEntity.ok(response);
68 } catch (Exception e) {
69 Map<String, Object> error = new HashMap<>();
70 error.put("success", false);
71 error.put("error", e.getMessage());
72 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
73 }
74 }
75
76 /**
77 * GET /api/currency/supported - Get list of supported currencies
78 */
79 @GetMapping("/supported")
80 public ResponseEntity<Map<String, Object>> getSupportedCurrencies() {
81 try {
82 Set<String> currencies = currencyService.getSupportedCurrencies();
83
84 Map<String, Object> response = new HashMap<>();
85 response.put("success", true);
86 response.put("currencies", currencies);
87 response.put("total", currencies.size());
88
89 return ResponseEntity.ok(response);
90 } catch (Exception e) {
91 Map<String, Object> error = new HashMap<>();
92 error.put("success", false);
93 error.put("error", e.getMessage());
94 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
95 }
96 }
97
98 /**
99 * POST /api/admin/currency/refresh - Manually trigger exchange rate refresh
100 */
101 @PostMapping("/admin/refresh")
102 public ResponseEntity<Map<String, Object>> refreshRates() {
103 try {
104 currencyService.manualRefresh();
105
106 Map<String, Object> response = new HashMap<>();
107 response.put("success", true);
108 response.put("message", "Exchange rates refreshed successfully");
109
110 return ResponseEntity.ok(response);
111 } catch (IllegalStateException e) {
112 Map<String, Object> error = new HashMap<>();
113 error.put("success", false);
114 error.put("error", e.getMessage());
115 return ResponseEntity.status(HttpStatus.CONFLICT).body(error);
116 } catch (Exception e) {
117 Map<String, Object> error = new HashMap<>();
118 error.put("success", false);
119 error.put("error", e.getMessage());
120 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
121 }
122 }
123
124 /**
125 * GET /api/currency/rate/{from}/{to} - Get specific exchange rate
126 */
127 @GetMapping("/rate/{from}/{to}")
128 public ResponseEntity<Map<String, Object>> getSpecificRate(
129 @PathVariable String from,
130 @PathVariable String to) {
131
132 try {
133 Double rate = currencyService.getRate(from, to);
134
135 Map<String, Object> response = new HashMap<>();
136 response.put("success", true);
137 response.put("fromCurrency", from);
138 response.put("toCurrency", to);
139 response.put("rate", rate);
140
141 return ResponseEntity.ok(response);
142 } catch (Exception e) {
143 Map<String, Object> error = new HashMap<>();
144 error.put("success", false);
145 error.put("error", e.getMessage());
146 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(error);
147 }
148 }
149 }
150