-
Notifications
You must be signed in to change notification settings - Fork 2
Criação da camada de serviço EmailService #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoaoVictorGI
merged 10 commits into
master
from
26-criação-da-camada-de-serviço-emailservice
Dec 1, 2025
The head ref may contain hidden characters: "26-cria\u00E7\u00E3o-da-camada-de-servi\u00E7o-emailservice"
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c3140f
feat: Criação da camada de serviço EmailService
lucasbdourado d1538c9
Merge branch 'master' into 26-criação-da-camada-de-serviço-emailservice
lucasbdourado b221932
Merge remote-tracking branch 'origin/master' into 26-criação-da-camad…
lucasbdourado 8f8fb5f
Merge branch '26-criação-da-camada-de-serviço-emailservice' of https:…
lucasbdourado 2718689
fix: Alteração de nomenclatura de variavel para repository
lucasbdourado 1114074
fix: Atualização dos testes para cobrir 100% da classe de Reminder.
lucasbdourado b4ae702
Merge remote-tracking branch 'origin/master' into 26-criação-da-camad…
lucasbdourado 50a72f1
fix: Criação de testes de Controller para findAll
lucasbdourado 3b192d3
fix: Formatação de código
lucasbdourado 7b8f6da
fix: Ajustes nos testes para a camada reminderService
lucasbdourado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
53 changes: 53 additions & 0 deletions
53
src/main/java/br/com/springnoobs/reminderapi/mail/service/EmailService.java
This file contains hidden or 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,53 @@ | ||
| package br.com.springnoobs.reminderapi.mail.service; | ||
|
|
||
| import br.com.springnoobs.reminderapi.mail.engine.MailEngine; | ||
| import br.com.springnoobs.reminderapi.reminder.entity.Reminder; | ||
| import br.com.springnoobs.reminderapi.user.entity.Contact; | ||
| import java.time.ZoneId; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class EmailService { | ||
|
|
||
| private final MailEngine mailEngine; | ||
|
|
||
| private static final DateTimeFormatter DATE_FORMATTER = | ||
| DateTimeFormatter.ofPattern("dd/MM/yyyy").withZone(ZoneId.of("America/Sao_Paulo")); | ||
|
|
||
| public EmailService(MailEngine mailEngine) { | ||
| this.mailEngine = mailEngine; | ||
| } | ||
|
|
||
| public void send(Reminder reminder) { | ||
| if (reminder.getUser() == null) { | ||
| throw new RuntimeException("User not found"); | ||
| } | ||
|
|
||
| Contact contact = reminder.getUser().getContact(); | ||
|
|
||
| Map<String, String> variables = buildEmailVariables(contact, reminder, "#"); | ||
|
|
||
| mailEngine.sendEmail(variables); | ||
| } | ||
|
|
||
| private Map<String, String> buildEmailVariables(Contact contact, Reminder reminder, String disableUrl) { | ||
| Map<String, String> map = new HashMap<>(); | ||
|
|
||
| map.put("name", contact.getUser().getFirstName()); | ||
| map.put("email", contact.getEmail()); | ||
| map.put("title", reminder.getTitle()); | ||
| map.put( | ||
| "remind_at", | ||
| reminder.getRemindAt() != null | ||
| ? DATE_FORMATTER.format(reminder.getRemindAt()) | ||
| : DATE_FORMATTER.format(reminder.getDueDate())); | ||
| map.put("due_date", DATE_FORMATTER.format(reminder.getDueDate())); | ||
| map.put("disable_notification_url", disableUrl); | ||
| map.put("subject", "Lembrete" + " - " + reminder.getTitle()); | ||
|
|
||
| return map; | ||
| } | ||
| } |
4 changes: 3 additions & 1 deletion
4
...in/java/br/com/springnoobs/reminderapi/reminder/dto/request/CreateReminderRequestDTO.java
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package br.com.springnoobs.reminderapi.reminder.dto.request; | ||
|
|
||
| import br.com.springnoobs.reminderapi.user.dto.request.CreateUserRequestDTO; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import java.time.Instant; | ||
|
|
||
| public record CreateReminderRequestDTO( | ||
| @NotBlank(message = "Title must not be null") String title, | ||
| @NotNull(message = "DueDate must not be null") Instant dueDate) {} | ||
| @NotNull(message = "DueDate must not be null") Instant dueDate, | ||
| @NotNull(message = "User must not be null") CreateUserRequestDTO user) {} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.