Skip to content

Conversation

@Isnael07
Copy link

Evidências do funcionamento dos endpoints

CREATE

http-post.mp4

READ(FindAll)

http-get.getAll.mp4

READ(FindOne)

http-get.mp4

UPDATE

http-put.mp4

DELETE

http-delete.mp4

CREATE VALIDAÇÃO UNICIDADE

http-post.valida.unicidade.mp4

CREATE VALIDAÇÃO FORMATO

http-post.valida.formato.mp4

@coderabbitai
Copy link

coderabbitai bot commented Sep 26, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 193-backend--criar-area-da-saude

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No findById, atualmente retorna 204 No Content quando não encontra. Mas o service já lança EntidadeNaoEncontradaException, que provavelmente está mapeada para 404. Isso pode gerar inconsistência. Sugestão: deixar apenas a exceção do service, sem o .map(...).orElse(...).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O método update não é necessário, já que o save cobre create/update no JPA. Pode ser removido para simplificação.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update repete o mesmo que save. Se remover de AreaSaudeRepository, pode simplificar aqui também.

@csabrina
Copy link

Preparing PR description...

1 similar comment
@csabrina
Copy link

Preparing PR description...

@csabrina
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential N+1 Issue

The findById method in AreaSaudeService throws an exception if the area is not found, but it does not handle potential performance issues when loading related entities. Ensure that any related data loading is optimized to avoid N+1 query problems.

public Optional<AreaSaudeResponseDTO> findById(Integer id){
    Optional<AreaSaudeResponseDTO> dto =
            this.repository.findById(id).map(AreaSaudeMapper::toResponseDTO);

    if (dto.isEmpty()) throw new EntidadeNaoEncontradaException("Área de saúde não encontrada");

    return dto;
}
Cross-Origin Configuration

The @CrossOrigin annotation is configured to allow only http://localhost:3000. This should be reviewed for production environments to ensure appropriate CORS policies are in place.

@CrossOrigin(origins = "http://localhost:3000")

@csabrina
Copy link

csabrina commented Sep 30, 2025

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Impact
Possible issue
Validar entrada nula no save

O método save não está validando se o campo 'area' do DTO é nulo ou vazio antes de
verificar a existência. Isso pode causar um NullPointerException se o campo estiver
inválido.

api/profissional-da-saude/src/main/java/br/org/apae/profissional_da_saude/application/service/AreaSaudeService.java [26-35]

 public AreaSaudeResponseDTO save(AreaSaudeCreateDTO dto){
+    if (dto.getArea() == null || dto.getArea().trim().isEmpty()) {
+        throw new ValidacaoNegocioException("A área de saúde não pode ser nula ou vazia.");
+    }
     if (this.repository.existsByArea(dto.getArea())){
         throw new ValidacaoNegocioException("Área de saúde já cadastrada.");
     }
     AreaSaude domain = new AreaSaude(
             dto.getArea()
     );
     AreaSaude saved = this.repository.save(domain);
     return AreaSaudeMapper.toResponseDTO(saved);
 }
Suggestion importance[1-10]: 8

__

Why: O método save pode causar um NullPointerException se o campo area do DTO for nulo ou vazio, pois não é validado antes de ser usado. A sugestão corrige isso adicionando uma verificação inicial.

Medium
Validar entrada nula no update

O método update não está validando se o campo 'area' do DTO é nulo ou vazio antes de
atualizar. Isso pode resultar em uma área de saúde vazia, o que pode ser
indesejável.

api/profissional-da-saude/src/main/java/br/org/apae/profissional_da_saude/application/service/AreaSaudeService.java [54-63]

 public AreaSaudeResponseDTO update(Integer id, AreaSaudeUpdateDTO dto){
     AreaSaude existe = this.repository.findById(id)
             .orElseThrow(()-> new EntidadeNaoEncontradaException("Área de saúde não encontrada"));
+
+    if (dto.getArea() == null || dto.getArea().trim().isEmpty()) {
+        throw new ValidacaoNegocioException("A área de saúde não pode ser nula ou vazia.");
+    }
 
     Optional.ofNullable(dto.getArea()).ifPresent(existe::setArea);
 
     AreaSaude saved = this.repository.save(existe);
 
     return  AreaSaudeMapper.toResponseDTO(saved);
 }
Suggestion importance[1-10]: 7

__

Why: O método update pode permitir a atualização com uma área de saúde vazia, o que pode ser indesejável. A sugestão adiciona validação para evitar isso, melhorando a integridade dos dados.

Medium
General
Inicializar ID no construtor

O construtor que recebe apenas a área não inicializa o ID, o que pode causar
problemas se o objeto for usado em contextos onde o ID é necessário antes de ser
persistido.

api/profissional-da-saude/src/main/java/br/org/apae/profissional_da_saude/domain/model/AreaSaude.java [14-16]

 public AreaSaude(String area) {
     this.area = area;
+    this.id = null; // ou uma lógica para gerar um ID temporário, se aplicável
 }
Suggestion importance[1-10]: 3

__

Why: O construtor AreaSaude(String area) não inicializa o ID, o que pode causar confusão se o objeto for usado em contextos onde o ID é esperado. No entanto, essa alteração tem impacto menor e é mais uma questão de estilo ou clareza.

Low

@IFPBEsp IFPBEsp deleted a comment from csabrina Oct 7, 2025
@Isnael07
Copy link
Author

Sugestões adotadas 2/3 do PR Code Suggestions

@sabrinaccst sabrinaccst removed the request for review from isaacoliveeira October 23, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants