Skip to content

Commit

Permalink
Merge pull request #3 from GuilhermeDoSantoss/Develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
GuilhermeDoSantoss authored Jan 18, 2025
2 parents 5ebc133 + 714a3ba commit af27efa
Show file tree
Hide file tree
Showing 31 changed files with 877 additions and 0 deletions.
9 changes: 9 additions & 0 deletions DockerFile
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"]
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-hc5</artifactId>
<version>13.5</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableFeignClients
@EnableScheduling
public class BffAgendadorTarefasApplication {

public static void main(String[] args) {
Expand Down
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);
}

}

}
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;

}
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;

}
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;

}
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;
}
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;
}
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;

}
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;
}
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;
}
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;
}
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);
}

}

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
}
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);
}

}

Loading

0 comments on commit af27efa

Please sign in to comment.