Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog List API Endpoint #3

Open
7 tasks
Pythonian opened this issue Jul 20, 2024 · 1 comment
Open
7 tasks

Blog List API Endpoint #3

Pythonian opened this issue Jul 20, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Pythonian
Copy link
Owner

Pythonian commented Jul 20, 2024

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 page and page_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 is 1.
    • page_size: The number of blog posts per page. Default is 10.
  • 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

  1. 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.
  2. 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.
  3. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code.
    • Confirm that the response body contains an appropriate error message.
  4. Invalid Page or Page Size Parameters

    • Send requests with invalid page or page_size parameters (e.g., negative numbers, non-integer values).
    • Verify that the endpoint returns a 400 Bad Request status code and an appropriate error message.
  5. 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 Allowed status code.
  6. Soft-Deleted Blog Post Access Control

    • Ensure that soft-deleted blog posts are filtered out for users.
@Pythonian Pythonian self-assigned this Jul 22, 2024
@Pythonian Pythonian added the enhancement New feature or request label Jul 22, 2024
@Pythonian
Copy link
Owner Author

Will it be necessary to include a "url" to the blog post in the response API?

Example: "url": f"/api/v1/blogs/{blog.id}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant