Skip to content

Conversation

@umaranit
Copy link

This pull request includes several changes to the CommentServiceImpl and FileServiceImpl classes to add new functionality and improve the codebase. The most important changes include the addition of methods for retrieving comments by ID and by post ID, as well as the introduction of a sample method demonstrating deeply nested conditionals.

@umaranit umaranit requested a review from Copilot April 11, 2025 05:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces new methods for retrieving comments by ID and by post ID in CommentServiceImpl and a sample method demonstrating deeply nested conditionals in FileServiceImpl.

  • Added SampleNestedIfMethod to FileServiceImpl to illustrate deeply nested conditionals.
  • Introduced new methods (getCommentById and getAllCommentsByPostId) in CommentServiceImpl; however, duplicate definitions are present.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/main/java/com/codewithdurgesh/blog/services/impl/FileServiceImpl.java Added SampleNestedIfMethod with deeply nested conditionals
src/main/java/com/codewithdurgesh/blog/services/impl/CommentServiceImpl.java New methods for retrieving comments with duplicate implementations present

Comment on lines +75 to 99
@Override
public CommentDto getCommentById(Integer commentId) {

Comment comment = this.commentRepo.findById(commentId).get(); // Should handle Optional properly
return null; // Should use modelMapper to map Comment to CommentDto
}

@Override
public List<CommentDto> getAllCommentsByPostId(Integer postId) {

List<Comment> comments = this.commentRepo.findByPostId(postId); // Assuming such a method exists in CommentRepo

// Issue 1: Null check for comments is missing.
// Issue 2: Improper exception handling for a case where comments list might be empty or null.

List<CommentDto> commentDtos = comments.stream()
.map(comment -> this.modelMapper.map(comment, CommentDto.class))
.collect(Collectors.toList());

return commentDtos;


}

}
Copy link

Copilot AI Apr 11, 2025

Choose a reason for hiding this comment

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

Duplicate implementations of getCommentById and getAllCommentsByPostId methods found; please remove the redundant definitions to avoid conflicts.

Suggested change
@Override
public CommentDto getCommentById(Integer commentId) {
Comment comment = this.commentRepo.findById(commentId).get(); // Should handle Optional properly
return null; // Should use modelMapper to map Comment to CommentDto
}
@Override
public List<CommentDto> getAllCommentsByPostId(Integer postId) {
List<Comment> comments = this.commentRepo.findByPostId(postId); // Assuming such a method exists in CommentRepo
// Issue 1: Null check for comments is missing.
// Issue 2: Improper exception handling for a case where comments list might be empty or null.
List<CommentDto> commentDtos = comments.stream()
.map(comment -> this.modelMapper.map(comment, CommentDto.class))
.collect(Collectors.toList());
return commentDtos;
}
}
// Removed redundant definitions of getCommentById and getAllCommentsByPostId methods.
}

Copilot uses AI. Check for mistakes.
boolean isMember = false;

// Deeply nested conditionals
if (age > 18) {
Copy link

Copilot AI Apr 11, 2025

Choose a reason for hiding this comment

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

Consider refactoring the deeply nested conditional statements to simplify the logic and improve readability.

Copilot uses AI. Check for mistakes.
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.

2 participants