-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from diegosneves/feat/invoices
feat(envio de email) 🔖 Remover o código da estratégia de pagamento e melhorar a lógica de negócios
- Loading branch information
Showing
32 changed files
with
546 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.9' | ||
|
||
services: | ||
email_server: | ||
image: diegoneves/email-server:latest | ||
restart: always | ||
container_name: email_server | ||
networks: | ||
- pedido-bridge | ||
ports: | ||
- "8081:8081" | ||
|
||
racha-pedido-app: | ||
image: diegoneves/racha-pedido:latest | ||
container_name: racha-pedido | ||
ports: | ||
- "8080:8080" | ||
depends_on: | ||
- email_server | ||
networks: | ||
- pedido-bridge | ||
environment: | ||
- EMAIL_HOST=email_server | ||
- EMAIL_PORT=8081 | ||
|
||
|
||
networks: | ||
pedido-bridge: | ||
driver: bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/diegosneves/github/rachapedido/adapter/HttpAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package diegosneves.github.rachapedido.adapter; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@Getter(AccessLevel.PROTECTED) | ||
@Setter(AccessLevel.PROTECTED) | ||
public abstract class HttpAdapter { | ||
|
||
protected RestTemplateSimpleWebClient restTemplateSimpleWebClient; | ||
protected HttpHeaders headers; | ||
|
||
protected HttpAdapter() { | ||
this.headers = new HttpHeaders(); | ||
this.headers.setContentType(MediaType.APPLICATION_JSON); | ||
this.headers.setAccept(List.of(MediaType.APPLICATION_JSON)); | ||
this.restTemplateSimpleWebClient = new RestTemplateSimpleWebClient(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/diegosneves/github/rachapedido/adapter/RestTemplateSimpleWebClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package diegosneves.github.rachapedido.adapter; | ||
|
||
import lombok.Getter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Component | ||
@Getter | ||
public class RestTemplateSimpleWebClient { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
public RestTemplateSimpleWebClient() { | ||
this.restTemplate = new RestTemplate(); | ||
} | ||
|
||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/diegosneves/github/rachapedido/adapter/SendEmailAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package diegosneves.github.rachapedido.adapter; | ||
|
||
import diegosneves.github.rachapedido.core.BankAccount; | ||
import diegosneves.github.rachapedido.exceptions.ErroHandler; | ||
import diegosneves.github.rachapedido.model.Item; | ||
import diegosneves.github.rachapedido.model.NotificationEmail; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestClientException; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@Slf4j | ||
public class SendEmailAdapter extends HttpAdapter { | ||
|
||
private final String url; | ||
|
||
@Autowired | ||
public SendEmailAdapter(@Value("${spring.api.url.send-email}") String url) { | ||
this.url = url; | ||
} | ||
|
||
public void sendNotificationEmail(NotificationEmail notificationEmail) { | ||
// Item itemII = Item.builder() | ||
// .name("Item II") | ||
// .price(2.00) | ||
// .build(); | ||
// | ||
// Item itemIII = Item.builder() | ||
// .name("Item III") | ||
// .price(8.00) | ||
// .build(); | ||
// notificationEmail = NotificationEmail.builder() | ||
// .email("[email protected]") | ||
// .consumerName("Diego Neves") | ||
// .total(10.00) | ||
// .itens(List.of(itemII, itemIII)) | ||
// .link(BankAccount.PICPAY.paymentLink()) | ||
// .build(); | ||
|
||
try { | ||
String response = this.restTemplateSimpleWebClient | ||
.getRestTemplate() | ||
.postForEntity(this.url, notificationEmail, String.class) | ||
.getBody(); | ||
log.info(response); | ||
} catch (RestClientException e) { | ||
log.error(ErroHandler.EMAIL_SEND_FAILURE.errorMessage(notificationEmail.getEmail()), e); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/diegosneves/github/rachapedido/core/BankAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package diegosneves.github.rachapedido.core; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public enum BankAccount { | ||
|
||
@JsonProperty(value = "nubank") | ||
NUBANK("https://nubank.com.br/cobrar/5h2au/658235a8-f38a-4cf5-881c-1de7114d66c7"), | ||
@JsonProperty(value = "picpay") | ||
PICPAY("https://app.picpay.com/user/diego.neves215"); | ||
|
||
private final String billingLink; | ||
|
||
BankAccount(String billingLink) { | ||
this.billingLink = billingLink; | ||
} | ||
|
||
public String paymentLink() { | ||
return this.billingLink; | ||
} | ||
|
||
} |
16 changes: 0 additions & 16 deletions
16
src/main/java/diegosneves/github/rachapedido/core/PagBank.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/diegosneves/github/rachapedido/core/contract/PaymentStrategy.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.