diff --git a/.github/custom-instructions.md b/.github/custom-instructions.md new file mode 100644 index 0000000..ac5bbc4 --- /dev/null +++ b/.github/custom-instructions.md @@ -0,0 +1,14 @@ +### General + +Rules +- For any change you make always add a comment 'Generated by Copilot - start' at the start of code block generated by you and 'Generated by Copilot - end' at the end of code block which is generated by you. +-For any change you make always add a comment 'Lines of code suggested - X' at the end of code block generated by you + +- Avoid hardcoding values in the codebase, such as database connection strings, API keys, or URLs. +- Use environment variables to store configuration values. +- Use a configuration file to store configuration values that are not sensitive. +- Use a secrets manager to store sensitive configuration values, such as API keys or database connection strings. +- Use a `.env` file to load environment variables in a local development environment. +- Use a `.env.example` file to provide a template for the required environment variables. +- Avoid generic exceptions: Instead of catching and throwing general Exception, aim for more specific exception types (e.g., IOException, NullPointerException, DataFormatException). +- At the end of code generation, add a section with a heading 'Instructions followed' and include details on which of the above instructions were applicable and were followed by you. \ No newline at end of file diff --git a/code-generation.md b/code-generation.md new file mode 100644 index 0000000..fad9bcd --- /dev/null +++ b/code-generation.md @@ -0,0 +1,23 @@ +# General Guidelines +Rules +-For any change you make always add a comment 'Generated by Copilot - start' at the start of code block generated by you and 'Generated by Copilot - end' at the end of code block which is generated by you. +-For any change you make always add a comment 'Lines of code suggested - X' at the end of code block generated by you + +- For any change you make always fetch the current time stamp and add as a comment at the end of code block which is generated by you. + +- For any change you make always fetch the current selected LLM model and add as a comment at the end of code block which is generated by you. + + +## API Design + +- Follow RESTful principles for API design. +- Use appropriate HTTP methods (e.g., `GET`, `POST`, `PUT`, `DELETE`). +- Provide clear and consistent API documentation using Swagger. +- Implement proper authentication and authorization using JWT. + +## Security + +- Sanitize user inputs to prevent injection attacks. +- Use strong passwords and hashing algorithms. +- Protect sensitive data using encryption. +- Follow secure coding practices to prevent vulnerabilities. \ No newline at end of file diff --git a/code-review.md b/code-review.md new file mode 100644 index 0000000..4d16994 --- /dev/null +++ b/code-review.md @@ -0,0 +1,10 @@ +- For any code review suggestions that you do, clearly mark the suggestion with comments example shown below: +// Copilot Review Suggestion - start +{suggested changes or improvements} +// Copilot Review Suggestion - end + +# Additional Guidelines +- Ensure all code blocks are properly formatted. +- Review generated code for accuracy and relevance before finalizing. +## Additional Instructions +Revalidate before responding. Think step by step. \ No newline at end of file diff --git a/commit-message.md b/commit-message.md new file mode 100644 index 0000000..1c05278 --- /dev/null +++ b/commit-message.md @@ -0,0 +1,15 @@ +Don’t end commit message summaries with punctuation +Don’t write all words in capital letters +Use the imperative verb form +Use the present tense +Use the active voice +Explain what the commit does in crisp, clear language +Limit the summary to 50 characters +Include bug id or issue number where possible + + + + + + + diff --git a/complete backed course.pptx b/complete backed course.pptx deleted file mode 100644 index 56481d3..0000000 Binary files a/complete backed course.pptx and /dev/null differ diff --git a/read-me.md b/read-me.md new file mode 100644 index 0000000..cdda0cf --- /dev/null +++ b/read-me.md @@ -0,0 +1 @@ +test commit \ No newline at end of file diff --git a/src/main/java/com/codewithdurgesh/blog/services/impl/CommentServiceImpl.java b/src/main/java/com/codewithdurgesh/blog/services/impl/CommentServiceImpl.java index 0b7d0c1..53c68b2 100644 --- a/src/main/java/com/codewithdurgesh/blog/services/impl/CommentServiceImpl.java +++ b/src/main/java/com/codewithdurgesh/blog/services/impl/CommentServiceImpl.java @@ -24,6 +24,7 @@ public class CommentServiceImpl implements CommentService { @Autowired private ModelMapper modelMapper; + @Override public CommentDto createComment(CommentDto commentDto, Integer postId) { @@ -47,4 +48,28 @@ public void deleteComment(Integer commentId) { this.commentRepo.delete(com); } + @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 getAllCommentsByPostId(Integer postId) { + + List 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 commentDtos = comments.stream() + .map(comment -> this.modelMapper.map(comment, CommentDto.class)) + .collect(Collectors.toList()); + + return commentDtos; + + +} + } diff --git a/src/main/java/com/codewithdurgesh/blog/services/impl/FileServiceImpl.java b/src/main/java/com/codewithdurgesh/blog/services/impl/FileServiceImpl.java index c06a48b..bed1c74 100644 --- a/src/main/java/com/codewithdurgesh/blog/services/impl/FileServiceImpl.java +++ b/src/main/java/com/codewithdurgesh/blog/services/impl/FileServiceImpl.java @@ -52,4 +52,33 @@ public InputStream getResource(String path, String fileName) throws FileNotFound return is; } + public static void SampleNestedIfMethod(String[] args) { + int age = 25; + String country = "USA"; + boolean hasPermission = true; + boolean isMember = false; + + // Deeply nested conditionals + if (age > 18) { + if (country.equals("USA")) { + if (hasPermission) { + if (isMember) { + System.out.println("Access granted: Adult from USA, with permission, and is a member."); + } else { + System.out.println("Access denied: Adult from USA, with permission, but not a member."); + } + } else { + System.out.println("Access denied: Adult from USA, without permission."); + } + } else { + System.out.println("Access denied: Adult, but not from USA."); + } + } else { + System.out.println("Access denied: Underage."); + } + } + + + + } diff --git a/unit-test.md b/unit-test.md new file mode 100644 index 0000000..bc654b2 --- /dev/null +++ b/unit-test.md @@ -0,0 +1,7 @@ +# Unit Test Instructions + +1. **Test Framework**: Use JUnit 5 for writing unit tests. +2. **Test Naming**:for each unit test write the name of unit test in the following format: `methodUnderTest_inputGiven_expectedOutput` +3. **Assertions**: Use `assertEquals`, `assertTrue`, `assertFalse`, and `assertThrows` for assertions. +4. **Mocking**: Use Mockito for mocking dependencies. +5. **Test Coverage**: Ensure that all public methods have corresponding unit tests.