feat(comments): added Get Article comments API #37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new feature to retrieve paginated comments for articles, including one level of child comments. It adds a new controller, request validation, resource classes, and database seeding for testing, as well as updates the model and service layer. Comprehensive test coverage is also included.
New Feature: Retrieve Paginated Comments
Controller and API Endpoint
GetCommentsControllerto handle requests for fetching comments with pagination and child comments. It includes error handling and response formatting./articles/{article:slug}/comments.Request Validation and Resource Formatting
GetCommentsRequestfor validating query parameters such asper_page,page, andparent_id.CommentResourceto structure the JSON response for comments, including user details, content, and replies.Backend Enhancements
Model Updates
Commentmodel to includereplies_countandreplies_pageproperties, and added arepliesrelationship to fetch child comments. [1] [2]Service Layer
getArticleCommentsmethod inArticleServiceto fetch paginated comments with user details, reply counts, and limited child comments.Testing and Seeding
Database Seeder
ArticleCommentSeederto generate test data for articles, comments, and nested comments.Feature Tests
GetCommentsControllerto verify functionality, including successful responses, empty results, and error handling.