-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Develop an endpoint to handle requests to fetch and return all blog post data. If the data is fetched successfully, it will be returned to the client with a 200 OK status. If an error occurs, an appropriate error status will be returned.
Acceptance Criteria
- The endpoint fetches and returns a paginated blog post data ordered by the created date in descending order.
- Returns appropriate status codes and messages based on the response.
- Filters out soft-deleted blog posts for users.
- The endpoint does not require authentication.
Requirements
- Implement API endpoint for fetching blog post summaries.
- Fetch and return blog post data including: Title, Excerpt, Created at, Image url and ID.
- Implement pagination with query parameters
pageandpage_size. - Handle unexpected errors and return the appropriate status code.
- Ensure soft-deleted blog posts are not returned for users.
- Ensure the endpoint does not require authentication.
- Order blog post data by the created date in descending order.
Expected Outcome
- Visitors should be able to send a request to the backend to retrieve a paginated list of all blog post summaries.
- Visitors should receive appropriate status codes and responses based on the outcome of the request.
- Blog posts should be retrieved and returned in order of most recently created first.
Endpoints
[GET] /api/v1/blogs
-
Description: Fetches a paginated list of blog post summaries.
-
Query Parameters:
page: The page number to retrieve. Default is1.page_size: The number of blog posts per page. Default is10.
-
Success Response:
-
Status:
200 OK -
Body:
{ "count": 100, "next": "http://example.com/api/v1/blogs?page=2&page_size=10", "previous": null, "results": [ { "id": "id", "title": "My First Blog", "excerpt": "This is an excerpt from my first blog.", "image_url": "https://example.com/image1.jpg", "created_at": "2024-07-22T07:59:23.212142Z" }, ] }
-
-
Error Response:
-
Status:
500 Internal Server Error -
Body:
{ "error": "Internal server error." }
-
-
Invalid Method Response:
-
Status:
405 Method Not Allowed -
Body:
{ "error": "This method is not allowed." }
-
-
Bad Request Response:
-
Status:
400 Bad Request -
Body:
{ "error": "An invalid request was sent." }
-
Testing
Test Scenarios
-
Successful Retrieval of Paginated Blog Posts
- Ensure that the endpoint successfully retrieves a paginated list of blog posts.
- Verify that the response includes the total count, next and previous page URLs, and the results with title, excerpt, publish date, and author for each blog post.
- Confirm that the status code is
200 OK. - Confirm that the blog posts are ordered by the created date in descending order.
-
No Blog Posts Present
- Simulate a scenario where no blog posts are present in the database.
- Confirm that the response body contains an empty list.
-
Internal Server Error
- Simulate an internal server error to raise an exception.
- Verify that the endpoint returns a
500 Internal Server Errorstatus code. - Confirm that the response body contains an appropriate error message.
-
Invalid Page or Page Size Parameters
- Send requests with invalid
pageorpage_sizeparameters (e.g., negative numbers, non-integer values). - Verify that the endpoint returns a
400 Bad Requeststatus code and an appropriate error message.
- Send requests with invalid
-
Invalid Method
- Send a request using an invalid HTTP method (e.g., POST) to the endpoint.
- Verify that the endpoint returns a
405 Method Not Allowedstatus code.
-
Soft-Deleted Blog Post Access Control
- Ensure that soft-deleted blog posts are filtered out for users.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request