Skip to content

Commit 012e17b

Browse files
committed
create new service exchange to and from amount
create unit test service layer using spring cacheable cache every 1 minute and using feign
1 parent a61a58b commit 012e17b

32 files changed

+994
-1
lines changed

build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ ext {
2424

2525
dependencies {
2626
implementation 'org.springframework.boot:spring-boot-starter-web'
27+
implementation 'org.springframework.boot:spring-boot-starter-validation'
28+
implementation 'org.springframework.boot:spring-boot-starter-aop'
2729
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
2830
compileOnly 'org.projectlombok:lombok'
2931
annotationProcessor 'org.projectlombok:lombok'
32+
implementation "javax.validation:validation-api:${javaxValidationVersion}"
33+
3034
testImplementation 'org.springframework.boot:spring-boot-starter-test'
3135
}
3236

gradle.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mapstructVersion=1.4.2.Final
2+
javaxValidationVersion=2.0.1.Final
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package az.unitech.development.exchange.client;
2+
3+
import az.unitech.development.exchange.client.model.CurrencyResponse;
4+
import org.springframework.cloud.openfeign.FeignClient;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
8+
@FeignClient(name = "fastforex",
9+
url = "${api.fastforex.io}",
10+
primary = false,
11+
contextId = "currency-rates"
12+
)
13+
public interface CurrencyClient {
14+
15+
@GetMapping(value = "/fetch-all")
16+
CurrencyResponse getRatesBaseUSD(@RequestParam("api_key") String apiKey);
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package az.unitech.development.exchange.client.model;
2+
3+
import lombok.Data;
4+
5+
import java.math.BigDecimal;
6+
import java.util.Map;
7+
8+
@Data
9+
public class CurrencyResponse {
10+
11+
private String base;
12+
private Map<String, BigDecimal> results;
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package az.unitech.development.exchange.config;
2+
3+
import az.unitech.development.exchange.config.properties.CurrencyClientProperties;
4+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Configuration
8+
@EnableConfigurationProperties(CurrencyClientProperties.class)
9+
public class ApplicationPropertyConfiguration {
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package az.unitech.development.exchange.config;
2+
3+
import org.springframework.cloud.openfeign.EnableFeignClients;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@EnableFeignClients(basePackages = "az.unitech.development.exchange.client")
8+
public class FeignClientConfiguration {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package az.unitech.development.exchange.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.scheduling.annotation.EnableScheduling;
5+
6+
@Configuration
7+
@EnableScheduling
8+
public class SchedulerConfiguration {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package az.unitech.development.exchange.config.cache;
2+
3+
import org.springframework.cache.annotation.EnableCaching;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
@EnableCaching
8+
public class CacheConfiguration {
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package az.unitech.development.exchange.config.cache;
2+
3+
import az.unitech.development.exchange.config.properties.ApplicationConstants;
4+
import org.springframework.cache.annotation.CacheEvict;
5+
import org.springframework.scheduling.annotation.Scheduled;
6+
import org.springframework.stereotype.Component;
7+
8+
@Component
9+
public class CacheEvictScheduler {
10+
11+
@Scheduled(fixedDelay = ApplicationConstants.TIME_UNIT_MINUTE)
12+
@CacheEvict(ApplicationConstants.CACHE_CURRENCY)
13+
public void evictCurrencyCache() {
14+
}
15+
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package az.unitech.development.exchange.config.properties;
2+
3+
public final class ApplicationConstants {
4+
5+
public static final String CACHE_CURRENCY = "cacheCurrency";
6+
public static final long TIME_UNIT_MINUTE = 60 * 1000L;
7+
8+
private ApplicationConstants() {
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package az.unitech.development.exchange.config.properties;
2+
3+
import lombok.Data;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import org.springframework.boot.context.properties.ConfigurationProperties;
7+
8+
@Getter
9+
@Setter
10+
@ConfigurationProperties("api")
11+
public class CurrencyClientProperties {
12+
13+
public FastForex fastForex= new FastForex();
14+
15+
@Data
16+
public static class FastForex {
17+
private String apiKey;
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package az.unitech.development.exchange.controller;
2+
3+
import az.unitech.development.exchange.dto.request.ExchangeRequest;
4+
import az.unitech.development.exchange.dto.response.ExchangeResponse;
5+
import az.unitech.development.exchange.service.ExchangeService;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
import javax.validation.Valid;
12+
13+
@RestController
14+
@RequestMapping("/exchange")
15+
@RequiredArgsConstructor
16+
public class ExchangeController {
17+
18+
private final ExchangeService exchangeService;
19+
20+
@GetMapping("/calculate")
21+
public ExchangeResponse calculate(@Valid ExchangeRequest exchangeRequest) {
22+
return exchangeService.calculate(exchangeRequest);
23+
}
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
package az.unitech.development.exchange.dto;
2+
3+
public enum Currencies {
4+
5+
AED,
6+
AFN,
7+
ALL,
8+
AMD,
9+
ANG,
10+
AOA,
11+
ARS,
12+
AUD,
13+
AWG,
14+
AZN,
15+
BAM,
16+
BBD,
17+
BDT,
18+
BGN,
19+
BHD,
20+
BIF,
21+
BMD,
22+
BND,
23+
BOB,
24+
BOV,
25+
BRL,
26+
BSD,
27+
BTN,
28+
BWP,
29+
BYN,
30+
BZD,
31+
CAD,
32+
CDF,
33+
CHE,
34+
CHF,
35+
CHW,
36+
CLF,
37+
CLP,
38+
CNY,
39+
COP,
40+
COU,
41+
CRC,
42+
CUC,
43+
CUP,
44+
CVE,
45+
CZK,
46+
DJF,
47+
DKK,
48+
DOP,
49+
DZD,
50+
EGP,
51+
ERN,
52+
ETB,
53+
EUR,
54+
FJD,
55+
FKP,
56+
GBP,
57+
GEL,
58+
GHS,
59+
GIP,
60+
GMD,
61+
GNF,
62+
GTQ,
63+
GYD,
64+
HKD,
65+
HNL,
66+
HRK,
67+
HTG,
68+
HUF,
69+
IDR,
70+
ILS,
71+
INR,
72+
IQD,
73+
IRR,
74+
ISK,
75+
JMD,
76+
JOD,
77+
JPY,
78+
KES,
79+
KGS,
80+
KHR,
81+
KMF,
82+
KPW,
83+
KRW,
84+
KWD,
85+
KYD,
86+
KZT,
87+
LAK,
88+
LBP,
89+
LKR,
90+
LRD,
91+
LSL,
92+
LYD,
93+
MAD,
94+
MDL,
95+
MGA,
96+
MKD,
97+
MMK,
98+
MNT,
99+
MOP,
100+
MRU,
101+
MUR,
102+
MVR,
103+
MWK,
104+
MXN,
105+
MXV,
106+
MYR,
107+
MZN,
108+
NAD,
109+
NGN,
110+
NIO,
111+
NOK,
112+
NPR,
113+
NZD,
114+
OMR,
115+
PAB,
116+
PEN,
117+
PGK,
118+
PHP,
119+
PKR,
120+
PLN,
121+
PYG,
122+
QAR,
123+
RON,
124+
RSD,
125+
RUB,
126+
RWF,
127+
SAR,
128+
SBD,
129+
SCR,
130+
SDG,
131+
SEK,
132+
SGD,
133+
SHP,
134+
SLL,
135+
SOS,
136+
SRD,
137+
SSP,
138+
STN,
139+
SVC,
140+
SYP,
141+
SZL,
142+
THB,
143+
TJS,
144+
TMT,
145+
TND,
146+
TOP,
147+
TRY,
148+
TTD,
149+
TWD,
150+
TZS,
151+
UAH,
152+
UGX,
153+
USD,
154+
USN,
155+
UYI,
156+
UYU,
157+
UYW,
158+
UZS,
159+
VES,
160+
VND,
161+
VUV,
162+
WST,
163+
XAF,
164+
XAG,
165+
XAU,
166+
XBA,
167+
XBB,
168+
XBC,
169+
XBD,
170+
XCD,
171+
XDR,
172+
XOF,
173+
XPD,
174+
XPF,
175+
XPT,
176+
XSU,
177+
XTS,
178+
XUA,
179+
YER,
180+
ZAR,
181+
ZMW,
182+
ZWL;
183+
184+
public static Currencies of(String code) {
185+
if (code == null) {
186+
return null;
187+
}
188+
return Currencies.valueOf(code.toUpperCase());
189+
}
190+
191+
}

0 commit comments

Comments
 (0)