Skip to content

Commit f945ba5

Browse files
Romo4ka-botrleontiev
and
rleontiev
authored
refactor : Update api-gateway pattern (#2910)
Co-authored-by: rleontiev <[email protected]>
1 parent 6401b0f commit f945ba5

File tree

5 files changed

+132
-6
lines changed

5 files changed

+132
-6
lines changed

api-gateway/price-microservice/src/main/java/com/iluwatar/price/microservice/PriceController.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,27 @@
2424
*/
2525
package com.iluwatar.price.microservice;
2626

27-
import lombok.extern.slf4j.Slf4j;
27+
import lombok.RequiredArgsConstructor;
2828
import org.springframework.web.bind.annotation.GetMapping;
2929
import org.springframework.web.bind.annotation.RestController;
3030

3131

3232
/**
3333
* Exposes the Price microservice's endpoints.
3434
*/
35-
@Slf4j
3635
@RestController
36+
@RequiredArgsConstructor
3737
public class PriceController {
3838

39+
private final PriceService priceService;
40+
3941
/**
4042
* An endpoint for a user to retrieve a product's price.
4143
*
4244
* @return A product's price
4345
*/
4446
@GetMapping("/price")
4547
public String getPrice() {
46-
LOGGER.info("Successfully found price info");
47-
return "20";
48+
return priceService.getPrice();
4849
}
4950
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
4+
* The MIT License
5+
* Copyright © 2014-2022 Ilkka Seppälä
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package com.iluwatar.price.microservice;
26+
27+
/**
28+
* Service to get a product's price.
29+
*/
30+
public interface PriceService {
31+
32+
/**
33+
* Getting the price of a product.
34+
*
35+
* @return A product's price
36+
*/
37+
String getPrice();
38+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
4+
* The MIT License
5+
* Copyright © 2014-2022 Ilkka Seppälä
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package com.iluwatar.price.microservice;
26+
27+
import lombok.extern.slf4j.Slf4j;
28+
import org.springframework.stereotype.Service;
29+
30+
/**
31+
* {@inheritDoc}
32+
*/
33+
@Service
34+
@Slf4j
35+
public class PriceServiceImpl implements PriceService {
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
@Override
41+
public String getPrice() {
42+
LOGGER.info("Successfully found price info");
43+
return "20";
44+
}
45+
}

api-gateway/price-microservice/src/test/java/com/iluwatar/price/microservice/PriceControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
class PriceControllerTest {
3535

3636
@Test
37-
void testgetPrice() {
38-
var priceController = new PriceController();
37+
void getPriceTest() {
38+
var priceController = new PriceController(new PriceServiceImpl());
3939
var price = priceController.getPrice();
4040
assertEquals("20", price);
4141
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
3+
*
4+
* The MIT License
5+
* Copyright © 2014-2022 Ilkka Seppälä
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package com.iluwatar.price.microservice;
26+
27+
import org.junit.jupiter.api.Test;
28+
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
31+
/**
32+
* Test for Price Service
33+
*/
34+
class PriceServiceTest {
35+
36+
@Test
37+
void getPriceTest() {
38+
var priceService = new PriceServiceImpl();
39+
var price = priceService.getPrice();
40+
assertEquals("20", price);
41+
}
42+
}

0 commit comments

Comments
 (0)