Skip to content

Conversation

@mubbi
Copy link
Owner

@mubbi mubbi commented Jul 27, 2025

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

  • Added GetCommentsController to handle requests for fetching comments with pagination and child comments. It includes error handling and response formatting.
  • Added a new API route to fetch comments for a specific article: /articles/{article:slug}/comments.

Request Validation and Resource Formatting

  • Introduced GetCommentsRequest for validating query parameters such as per_page, page, and parent_id.
  • Created CommentResource to structure the JSON response for comments, including user details, content, and replies.

Backend Enhancements

Model Updates

  • Updated the Comment model to include replies_count and replies_page properties, and added a replies relationship to fetch child comments. [1] [2]

Service Layer

  • Added getArticleComments method in ArticleService to fetch paginated comments with user details, reply counts, and limited child comments.

Testing and Seeding

Database Seeder

  • Added ArticleCommentSeeder to generate test data for articles, comments, and nested comments.

Feature Tests

  • Implemented tests for GetCommentsController to verify functionality, including successful responses, empty results, and error handling.

@mubbi mubbi self-assigned this Jul 27, 2025
@mubbi mubbi merged commit 322cce3 into develop Jul 27, 2025
4 checks passed
@mubbi mubbi deleted the feature/article-comments-api branch July 27, 2025 15:58
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