-
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 #3 from GuilhermeDoSantoss/Develop
Develop
- Loading branch information
Showing
31 changed files
with
877 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM openjdk:17-jdk-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY target/bff-agendador-tarefas-0.0.1-SNAPSHOT.jar /app/bff-agendador-tarefas.jar | ||
|
||
EXPOSE 8083 | ||
|
||
CMD ["java", "-jar", "/app/bff-agendador-tarefas.jar"] |
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/guilhermesantos/bff_agendador_tarefas/businees/CronService.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,57 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees; | ||
|
||
import com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in.LoginRequestDTO; | ||
import com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out.TarefasDTOResponse; | ||
import com.guilhermesantos.bff_agendador_tarefas.businees.Enuns.StatusNotificacaoEnum; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.Value; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import static sun.security.jgss.GSSUtil.login; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class CronService { | ||
|
||
private final TarefasService tarefasService; | ||
private final EmailService emailService; | ||
private final UsuarioService usuarioService; | ||
|
||
@Value("${usuario.email}") | ||
private String email; | ||
|
||
@Value("${usuario.senha}") | ||
private String senha; | ||
|
||
@Scheduled(cron = "${cron.horario}") | ||
|
||
public void buscaTarefasProximaHora() { | ||
public LoginRequestDTO converterParaRequestDTO String token = login(converterParaRequestDTO()); | ||
log.info("Iniciada a busca de tarefas"); | ||
LocalDateTime horaFutura = LocalDateTime.now().plusHours(1); | ||
LocalDateTime horaFuturaMaisCinco = LocalDateTime.now().plusHours(1).plusMinutes(5); | ||
|
||
List<TarefasDTOResponse> listaTarefas = tarefasService.buscaTarefasAgendadasPorPeriodo | ||
(horaFutura, horaFuturaMaisCinco, token); | ||
log.info("Tarefas encontradas " + listaTarefas); | ||
listaTarefas.forEach(tarefa -> { | ||
emailService.enviaEmail(tarefa); | ||
log.info("Email enviado para o usuario " + tarefa.getEmailUsuario()); | ||
tarefasService.alteraStatus(StatusNotificacaoEnum.notificado, tarefa.getId(), | ||
token); | ||
}); | ||
log.info("Finalizada a busca e notificaçao dee tarefas"); | ||
public String login (LoginRequestDTO dto){ | ||
return usuarioService.loginUsuario(dto); | ||
} | ||
|
||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...in/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/in/EnderecoDTORequest.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,19 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class EnderecoDTORequest { | ||
|
||
private String rua; | ||
private Long numero; | ||
private String complemento; | ||
private String cidade; | ||
private String estado; | ||
private String cep; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/in/LoginRequestDTO.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,15 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in; | ||
|
||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class LoginRequestDTO { | ||
private String email; | ||
private String senha; | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...ain/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/in/TarefasDTORequest.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 com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.guilhermesantos.bff_agendador_tarefas.businees.Enuns.StatusNotificacaoEnum; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class TarefasDTORequest { | ||
|
||
|
||
private String nomeTrefa; | ||
private String descricao; | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss") | ||
private LocalDateTime dataEvento; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...in/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/in/TelefoneDTORequest.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,14 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class TelefoneDTORequest { | ||
|
||
private String numero; | ||
private String ddd; | ||
} |
19 changes: 19 additions & 0 deletions
19
...ain/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/in/UsuarioDTORequest.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,19 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class UsuarioDTORequest { | ||
|
||
private String nome; | ||
private String email; | ||
private String senha; | ||
private List<EnderecoDTORequest> enderecos; | ||
private List<TelefoneDTORequest> telefones; | ||
} |
20 changes: 20 additions & 0 deletions
20
.../java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/out/EnderecoDTOResponse.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,20 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class EnderecoDTOResponse { | ||
|
||
private Long id; | ||
private String rua; | ||
private Long numero; | ||
private String complemento; | ||
private String cidade; | ||
private String estado; | ||
private String cep; | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...n/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/out/TarefasDTOResponse.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,28 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
import com.guilhermesantos.bff_agendador_tarefas.businees.Enuns.StatusNotificacaoEnum; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class TarefasDTOResponse { | ||
|
||
private String id; | ||
private String nomeTrefa; | ||
private String descricao; | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss") | ||
private LocalDateTime dataCriacao; | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss") | ||
private LocalDateTime dataEvento; | ||
private String emailUsuario; | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy HH:mm:ss") | ||
private LocalDateTime dataAlteracao; | ||
private StatusNotificacaoEnum statusNotificacaoEnum; | ||
} |
15 changes: 15 additions & 0 deletions
15
.../java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/out/TelefoneDTOResponse.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,15 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class TelefoneDTOResponse { | ||
|
||
private Long id; | ||
private String numero; | ||
private String ddd; | ||
} |
19 changes: 19 additions & 0 deletions
19
...n/java/com/guilhermesantos/bff_agendador_tarefas/businees/DTO/out/UsuarioDTOResponse.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,19 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class UsuarioDTOResponse { | ||
|
||
private String nome; | ||
private String email; | ||
private String senha; | ||
private List<EnderecoDTOResponse> enderecos; | ||
private List<TelefoneDTOResponse> telefones; | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/guilhermesantos/bff_agendador_tarefas/businees/EmailService.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,21 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees; | ||
|
||
|
||
import com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out.TarefasDTOResponse; | ||
import com.guilhermesantos.bff_agendador_tarefas.infrastructure.client.EmailClient; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class EmailService { | ||
|
||
private final EmailClient emailClient; | ||
|
||
public void enviaEmail; void gravarTarefa(TarefasDTOResponse dto) { | ||
emailClient.enviarEmail(dto); | ||
} | ||
|
||
} | ||
|
5 changes: 5 additions & 0 deletions
5
.../java/com/guilhermesantos/bff_agendador_tarefas/businees/Enuns/StatusNotificacaoEnum.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,5 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees.Enuns; | ||
|
||
public enum StatusNotificacaoEnum { | ||
pendente, notificado, cancelado | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/guilhermesantos/bff_agendador_tarefas/businees/TarefasService.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,48 @@ | ||
package com.guilhermesantos.bff_agendador_tarefas.businees; | ||
|
||
|
||
import com.guilhermesantos.bff_agendador_tarefas.businees.DTO.in.TarefasDTORequest; | ||
import com.guilhermesantos.bff_agendador_tarefas.businees.DTO.out.TarefasDTOResponse; | ||
import com.guilhermesantos.bff_agendador_tarefas.businees.Enuns.StatusNotificacaoEnum; | ||
import com.guilhermesantos.bff_agendador_tarefas.infrastructure.client.TarefasClient; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TarefasService { | ||
|
||
private final TarefasClient tarefasClient; | ||
|
||
public TarefasDTOResponse gravarTarefa(String token, TarefasDTORequest dto) { | ||
return tarefasClient.gravarTarefas(dto, token); | ||
} | ||
|
||
public List<TarefasDTOResponse> buscaTarefasAgendadasPorPeriodo(LocalDateTime dataInicial, | ||
LocalDateTime dataFinal, | ||
String token) { | ||
|
||
return tarefasClient.buscaListaDeTarefasPorPeriodo(dataInicial, dataFinal, token); | ||
} | ||
|
||
public List<TarefasDTOResponse> buscaTarefasPorEmail(String token) { | ||
return tarefasClient.buscaTarefasPorEmail(token); | ||
} | ||
|
||
public void deletaTarefaPorId(String id, String token) { | ||
tarefasClient.deletaTarefaPorId(id, token); | ||
} | ||
|
||
public TarefasDTOResponse alteraStatus(StatusNotificacaoEnum status, String id, String token) { | ||
return tarefasClient.alteraStatusNotificacao(status, id, token); | ||
} | ||
|
||
public TarefasDTOResponse updateTarefas(TarefasDTORequest dto, String id, String token){ | ||
return tarefasClient.updadeTarefas(dto, id, token); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.