Skip to content

Commit 79dd07f

Browse files
committed
feat: status gateway
1 parent b8b1b29 commit 79dd07f

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

src/main/java/br/com/grupo63/techchallenge/payment/gateway/order/IOrderGateway.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import br.com.grupo63.techchallenge.payment.gateway.order.dto.OrderDTO;
44
import org.springframework.cloud.openfeign.FeignClient;
5-
import org.springframework.web.bind.annotation.PathVariable;
65
import org.springframework.web.bind.annotation.RequestMapping;
76
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RequestParam;
88

99
import java.util.Optional;
1010

11-
@FeignClient(name = "order", url = "/orders}")
11+
@FeignClient(name = "order", url = "${urls.baseurl}")
1212
public interface IOrderGateway {
1313

14-
@RequestMapping(method = RequestMethod.GET, value = "/{orderId}")
15-
Optional<OrderDTO> getOrderById(@PathVariable("orderId") Long orderId);
14+
@RequestMapping(method = RequestMethod.GET, value = "${urls.orders}")
15+
Optional<OrderDTO> getOrderById(@RequestParam("orderId") Long orderId);
1616

1717
}

src/main/java/br/com/grupo63/techchallenge/payment/gateway/production/IProductionGateway.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package br.com.grupo63.techchallenge.payment.gateway.status;
2+
3+
import org.springframework.cloud.openfeign.FeignClient;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RequestMethod;
6+
import org.springframework.web.bind.annotation.RequestParam;
7+
8+
@FeignClient(name = "status", url = "${urls.baseurl}")
9+
public interface IStatusGateway {
10+
11+
@RequestMapping(method = RequestMethod.POST, value = "${urls.status}/advance-status", consumes = "application/json")
12+
void advanceStatus(@RequestParam("orderId") Long orderId);
13+
14+
}

src/main/java/br/com/grupo63/techchallenge/payment/usecase/PaymentUseCase.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import br.com.grupo63.techchallenge.payment.gateway.order.dto.OrderDTO;
99
import br.com.grupo63.techchallenge.payment.gateway.payment.IMercadoPagoGateway;
1010
import br.com.grupo63.techchallenge.payment.gateway.payment.IPaymentGateway;
11+
import br.com.grupo63.techchallenge.payment.gateway.status.IStatusGateway;
1112
import lombok.RequiredArgsConstructor;
1213
import org.springframework.stereotype.Service;
1314

@@ -18,6 +19,7 @@ public class PaymentUseCase implements IPaymentUseCase {
1819
private final IMercadoPagoGateway mercadoPagoGateway;
1920
private final IOrderGateway orderGateway;
2021
private final IPaymentGateway paymentGateway;
22+
private final IStatusGateway statusGateway;
2123

2224
@Override
2325
public String startPayment(Long orderId) throws NotFoundException {
@@ -39,6 +41,8 @@ public void finishPayment(Long orderId) throws NotFoundException {
3941
payment.setStatus(PaymentStatus.PAID);
4042
paymentGateway.saveAndFlush(payment);
4143

44+
statusGateway.advanceStatus(orderId);
45+
4246
}
4347

4448
@Override

src/main/resources/application-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ jwt:
2222
token:
2323
key:
2424
public: "${JWT_PUBLIC_KEY:MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqStd8n4SGNM0eZhV/hzU+urHA5/IMZPoP9YQ9ZcLKWiX33nI6bSuZMCrLZcJExf63xS+uxDpGxM8Mnk2zOdl+lPwANXLzP1us5P1PyA3YPycW9J7C5YTQW0GiEL3M93ZX7vMJiVoBYblP3JPlYnoYlBORuc0JPk33KtfEZP+78qXpPHM8imYrJLe8ceiDLLFDU/nh5KC2dWAy3ci1ahoJ1Q9ELhp3IZLvOTX57H/T2VKOYOya5+ST41h+JjzI+qGTVnLcKaW+k25YLlVnkSspvdx98+yQDi7kbOTS6yRZHUPD6wPk/nUozpD0nZKccoH4W+zMwmQVtsAA6JCA9gfGwIDAQAB}"
25-
25+
urls:
26+
baseurl: 'http://localhost:8080'

src/main/resources/application-prod.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ spring:
66
username: ${DB_USERNAME:backend}
77
devtools:
88
add-properties: false
9+
urls:
10+
baseurl: '/'

src/main/resources/application.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ info:
4242

4343
docs:
4444
api:
45-
url: "${DOCS_API_URL:https://9ah1j49vm1.execute-api.us-east-2.amazonaws.com}"
45+
url: "${DOCS_API_URL:https://9ah1j49vm1.execute-api.us-east-2.amazonaws.com}"
46+
47+
urls:
48+
status: '/public/status'
49+
orders: '/public/orders'

src/test/java/br/com/grupo63/techchallenge/payment/PaymentIntegrationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import br.com.grupo63.techchallenge.payment.gateway.order.IOrderGateway;
1111
import br.com.grupo63.techchallenge.payment.gateway.order.dto.OrderDTO;
1212
import br.com.grupo63.techchallenge.payment.gateway.payment.*;
13+
import br.com.grupo63.techchallenge.payment.gateway.status.IStatusGateway;
1314
import br.com.grupo63.techchallenge.payment.usecase.PaymentUseCase;
1415
import lombok.SneakyThrows;
1516
import org.junit.jupiter.api.BeforeEach;
@@ -32,6 +33,8 @@ class PaymentIntegrationTest {
3233
private PaymentJpaRepository paymentJpaRepository;
3334
@Mock
3435
private IOrderGateway orderGateway;
36+
@Mock
37+
private IStatusGateway statusGateway;
3538

3639
@InjectMocks
3740
private PaymentJpaAdapter paymentJpaAdapter;
@@ -54,7 +57,7 @@ class PaymentIntegrationTest {
5457
void setUp() {
5558
MockitoAnnotations.openMocks(this);
5659
mercadoPagoGateway = new MercadoPagoGateway();
57-
paymentUseCase = new PaymentUseCase(mercadoPagoGateway, orderGateway, paymentJpaAdapter);
60+
paymentUseCase = new PaymentUseCase(mercadoPagoGateway, orderGateway, paymentJpaAdapter, statusGateway);
5861
paymentController = new PaymentController(paymentUseCase);
5962
paymentAPIController = new PaymentAPIController(paymentController);
6063
}

0 commit comments

Comments
 (0)