Skip to content

Commit

Permalink
[feat] Recorrência de agendamentos
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciosarodrigues committed Jan 5, 2024
1 parent 150c52b commit 26f6351
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 141 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>br.com.nivlabs</groupId>
<artifactId>cliniv-api</artifactId>
<version>v1.0.0</version>
<version>v1.1.0</version>
<name>CliNiv API</name>
<description>API da aplicação de CliNiv</description>
<packaging>jar</packaging>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/br/com/nivlabs/cliniv/ApplicationMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
@SpringBootApplication
@EnableEurekaClient
public class ApplicationMain {

public static AppSettings SETTINGS;
public static final String AMERICA_SAO_PAULO;

static {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package br.com.nivlabs.cliniv.config.security;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
Expand All @@ -21,9 +22,8 @@

/**
* Classe SecurityConfig.java
*
*
* @author <a href="mailto:[email protected]">Vinícios Rodrigues</a>
*
* @since 15 de set de 2019
*/
@Configuration
Expand All @@ -41,10 +41,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
private UserRepository userDao;

private static final String[] PUBLIC_MATCHES = {"/v2/**",
"/webjars/**",
"/swagger-ui/**",
"/api-docs/**",
"/swagger-resources/**"};
"/webjars/**",
"/swagger-ui/**",
"/api-docs/**",
"/swagger-resources/**"};

private static final String[] PUBLIC_MATCHES_GET = {"/server/", "/server", "/actuator/**", "/status", "/dashboard"};

Expand Down Expand Up @@ -73,23 +73,23 @@ protected void configure(HttpSecurity http) throws Exception {

/**
* Configura CORS
*
*
* @return CorsConfigurationSource
*/
@Bean
public CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration configCors = new CorsConfiguration().applyPermitDefaultValues();
configCors.setAllowedMethods(Arrays.asList("POST", "GET", "PUT", "DELETE", "OPTIONS"));
configCors.setAllowedHeaders(Arrays.asList("*"));
configCors.setAllowedOrigins(Arrays.asList("*"));
configCors.setAllowedMethods(List.of("POST", "GET", "PUT", "DELETE", "OPTIONS"));
configCors.setAllowedHeaders(List.of("*"));
configCors.setAllowedOrigins(List.of("*"));
source.registerCorsConfiguration("/**", configCors);
return source;
}

/**
* Define a estratégia de criptografia da API
*
*
* @return BCryptPasswordEncoder
*/
@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import br.com.nivlabs.cliniv.controller.filters.AppointmentFilters;
import br.com.nivlabs.cliniv.models.dto.AppointmentInfoDTO;
import br.com.nivlabs.cliniv.models.dto.AppointmentsResponseDTO;
import br.com.nivlabs.cliniv.service.appointment.AppointmentsService;
import br.com.nivlabs.cliniv.service.appointment.AppointmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "Agenda", description = "Endpoint - Operações da Agenda")
@RestController
@RequestMapping(value = "/appointment")
public class AppointmentController extends BaseController<AppointmentsService> {
public class AppointmentController extends BaseController<AppointmentService> {

@Operation(summary = "appointment-get", description = "Busca informações de agendamentos baseados num filtro")
@GetMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package br.com.nivlabs.cliniv.controller;

import javax.validation.constraints.NotNull;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand Down Expand Up @@ -68,7 +66,7 @@ public ResponseEntity<ReportLayoutInfoDTO> persist(@Validated @RequestBody(requi
@PostMapping("/{id}")
@PreAuthorize("hasAnyRole('RELATORIO_ESCRITA', 'RELATORIO_LEITURA', 'ADMIN')")
public ResponseEntity<DigitalDocumentDTO> generateReport(@Validated @RequestBody(required = true) ReportGenerationRequestDTO reportParam,
@NotNull @PathVariable("id") Long id) {
@PathVariable("id") Long id) {

return ResponseEntity.status(HttpStatus.CREATED).body(service.generateDocumentFromReportLayout(id, reportParam));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package br.com.nivlabs.cliniv.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import br.com.nivlabs.cliniv.service.supplier.SupplierService;
import io.swagger.v3.oas.annotations.tags.Tag;

@Tag(name = "Fornecedor", description = "Endpoint - Operações com Fornecedor")
@RestController
@RequestMapping(value = "/supplier")
public class SupplierController extends BaseController<SupplierService> {

@Autowired
private ApplicationEventPublisher publisher;
}
11 changes: 11 additions & 0 deletions src/main/java/br/com/nivlabs/cliniv/enums/IntervalType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package br.com.nivlabs.cliniv.enums;

/**
* Tipos de intervalos
*/
public enum IntervalType {
DAILY,
WEEKLY,
MONTHLY,
YEARLY
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package br.com.nivlabs.cliniv.exception;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import br.com.nivlabs.cliniv.models.exception.ErrorItem;
import com.netflix.discovery.shared.transport.TransportException;
import io.jsonwebtoken.ExpiredJwtException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataIntegrityViolationException;
Expand All @@ -18,17 +15,19 @@
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import br.com.nivlabs.cliniv.models.exception.ErrorItem;
import io.jsonwebtoken.ExpiredJwtException;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@ControllerAdvice
public class HandlerExceptions {

private Logger logger = LoggerFactory.getLogger(HandlerExceptions.class);
final private Logger logger = LoggerFactory.getLogger(HandlerExceptions.class);

/**
* Captura erros não esperados
*
*
* @param e
* @param req
* @return
Expand All @@ -37,14 +36,14 @@ public class HandlerExceptions {
public ResponseEntity<StandardErrorSpring> objetoNaoEncontrado(Throwable e, HttpServletRequest req) {
logger.error("Falha interna não esperada :: ", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(),
HttpStatus.INTERNAL_SERVER_ERROR.value(), "Falha interna", Arrays.asList(), e.getMessage(),
HttpStatus.INTERNAL_SERVER_ERROR.value(), "Falha interna", List.of(), e.getMessage(),
req.getRequestURI());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(err);
}

/**
* Captura erros de padrões da API
*
*
* @param e
* @param req
* @return
Expand All @@ -53,7 +52,7 @@ public ResponseEntity<StandardErrorSpring> objetoNaoEncontrado(Throwable e, Http
public ResponseEntity<StandardErrorSpring> validationException(HttpException e, HttpServletRequest req) {
logger.error("Erro da requisição", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(), e.getStatus().value(),
"Erro da requisição", Arrays.asList(), e.getMessage(), req.getRequestURI());
"Erro da requisição", List.of(), e.getMessage(), req.getRequestURI());

return ResponseEntity.status(e.getStatus()).body(err);
}
Expand All @@ -62,14 +61,14 @@ public ResponseEntity<StandardErrorSpring> validationException(HttpException e,
public ResponseEntity<StandardErrorSpring> expiredJwtException(ExpiredJwtException e, HttpServletRequest req) {
logger.error("Token expirado", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(), HttpStatus.UNAUTHORIZED.value(),
"Token expirado", Arrays.asList(), "Token expirado!", req.getRequestURI());
"Token expirado", List.of(), "Token expirado!", req.getRequestURI());

return ResponseEntity.status(err.getStatus()).body(err);
}

/**
* Trata exceções de propriedades inválidas
*
*
* @param e
* @param req
* @return
Expand All @@ -79,15 +78,15 @@ public ResponseEntity<StandardErrorSpring> objetoNaoEncontrado(HttpMessageNotRea
HttpServletRequest req) {
logger.error("Falha interna não esperada :: ", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(),
HttpStatus.UNPROCESSABLE_ENTITY.value(), "Propriedade não reconhecida", Arrays.asList(),
HttpStatus.UNPROCESSABLE_ENTITY.value(), "Propriedade não reconhecida", List.of(),
getPropertyMessageError(e), req.getRequestURI());

return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY).body(err);
}

/**
* Captura nome da propriedade inválida do corpo da requisição
*
*
* @param e
* @return
*/
Expand All @@ -100,7 +99,7 @@ private String getPropertyMessageError(HttpMessageNotReadableException e) {

/**
* Erro de validação
*
*
* @param e
* @param req
* @return
Expand All @@ -118,7 +117,7 @@ public ResponseEntity<StandardErrorSpring> methodArgumentNotValidException(Metho

/**
* Trata a falta de permissão
*
*
* @param e
* @param req
* @return
Expand All @@ -128,7 +127,7 @@ public ResponseEntity<StandardErrorSpring> methodArgumentNotValidException(Acces
HttpServletRequest req) {
logger.error("Acesso negado :: ", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(), HttpStatus.FORBIDDEN.value(),
"Sem permissões", Arrays.asList(), "Seu usuário não tem permissão para acessar este recurso",
"Sem permissões", List.of(), "Seu usuário não tem permissão para acessar este recurso",
req.getRequestURI());

return ResponseEntity.status(HttpStatus.FORBIDDEN).body(err);
Expand All @@ -139,17 +138,12 @@ public ResponseEntity<StandardErrorSpring> dataIntegrityViolationException(DataI
HttpServletRequest req) {
logger.error("Violação de Integridade :: ", e);
StandardErrorSpring err = new StandardErrorSpring(System.currentTimeMillis(), HttpStatus.UNPROCESSABLE_ENTITY.value(),
"Violação de Integridade", Arrays.asList(), "Violação de integridade, esta ação não pode ser concluída",
"Violação de Integridade", List.of(), "Violação de integridade, esta ação não pode ser concluída",
req.getRequestURI());

return ResponseEntity.status(HttpStatus.CONFLICT).body(err);
}

/**
*
* @param e
* @return
*/
private List<ErrorItem> getValidations(MethodArgumentNotValidException e) {
List<ErrorItem> errors = new ArrayList<>();
for (FieldError error : e.getBindingResult().getFieldErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@Schema(description = "Informações do agendamento")
public class AppointmentInfoDTO extends DataTransferObjectBase {

private static final long serialVersionUID = -7082539967186369611L;

@Schema(description = "Identificador único do agendamento")
private Long id;
Expand All @@ -36,6 +35,8 @@ public class AppointmentInfoDTO extends DataTransferObjectBase {
@Schema(description = "Situação atual do agendamento")
private AppointmentStatus status = AppointmentStatus.WAITING_CONFIRMATION;

private AppointmentRecurrenceSettingsDTO repeatSettings;

public AppointmentInfoDTO() {
super();
}
Expand Down Expand Up @@ -96,68 +97,25 @@ public void setCreatedAt(LocalDateTime createdAt) {
this.createdAt = createdAt;
}

@Override
public String toString() {
return "AppointmentInfoDTO [id=" + id + ", patient=" + patient + ", professional=" + professional + ", schedulingDateAndTime="
+ schedulingDateAndTime + ", createdAt=" + createdAt + ", annotation=" + annotation + ", status=" + status + "]";
public AppointmentRecurrenceSettingsDTO getRepeatSettings() {
return repeatSettings;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((annotation == null) ? 0 : annotation.hashCode());
result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((patient == null) ? 0 : patient.hashCode());
result = prime * result + ((professional == null) ? 0 : professional.hashCode());
result = prime * result + ((schedulingDateAndTime == null) ? 0 : schedulingDateAndTime.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
public void setRepeatSettings(AppointmentRecurrenceSettingsDTO repeatSettings) {
this.repeatSettings = repeatSettings;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AppointmentInfoDTO other = (AppointmentInfoDTO) obj;
if (annotation == null) {
if (other.annotation != null)
return false;
} else if (!annotation.equals(other.annotation))
return false;
if (createdAt == null) {
if (other.createdAt != null)
return false;
} else if (!createdAt.equals(other.createdAt))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (patient == null) {
if (other.patient != null)
return false;
} else if (!patient.equals(other.patient))
return false;
if (professional == null) {
if (other.professional != null)
return false;
} else if (!professional.equals(other.professional))
return false;
if (schedulingDateAndTime == null) {
if (other.schedulingDateAndTime != null)
return false;
} else if (!schedulingDateAndTime.equals(other.schedulingDateAndTime))
return false;
if (status != other.status)
return false;
return true;
public String toString() {
return "AppointmentInfoDTO{" +
"id=" + id +
", patient=" + patient +
", professional=" + professional +
", schedulingDateAndTime=" + schedulingDateAndTime +
", createdAt=" + createdAt +
", annotation='" + annotation + '\'' +
", status=" + status +
", repeatSettings=" + repeatSettings +
'}';
}

}
Loading

0 comments on commit 26f6351

Please sign in to comment.