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

[FEAT] Endpoint to Retrieve All Blog Posts by an Author #647

Open
15 tasks done
idehen-divine opened this issue Mar 2, 2025 · 0 comments
Open
15 tasks done

[FEAT] Endpoint to Retrieve All Blog Posts by an Author #647

idehen-divine opened this issue Mar 2, 2025 · 0 comments

Comments

@idehen-divine
Copy link

idehen-divine commented Mar 2, 2025

Description

Implement an endpoint to fetch all blog posts authored by a specific user using their author_id.

Acceptance Criteria

  • It should be a GET request at /api/v1/blogs/author/{author_id}.
  • It should retrieve all posts associated with the given author_id.
  • It should support pagination to optimize retrieval.
  • It should return structured JSON responses with relevant blog post details.

Purpose

This feature allows users to easily fetch all blog posts from a particular author, improving content accessibility.

Requirements

  1. Develop server-side logic to query the database based on author_id.
  2. Ensure pagination for handling large author datasets.
  3. Handle cases where the author has no blog posts.
  4. Write unit tests to validate the endpoint.

Expected Outcome

Users should be able to retrieve all blog posts from a specific author efficiently.

Tasks

  • Create an endpoint (GET: /api/v1/blogs/author/{author_id}).
  • Query the database for blogs belonging to the author.
  • Implement pagination for large results.
  • Return a structured JSON response.
  • Handle edge cases (e.g., author not found, no blog posts).
  • Write unit tests to validate functionality.

Example Request

curl -X GET "{rootdomain}/api/v1/blogs/author/123" \
     -H "Content-Type: application/json"

Example Responses

  • Success Response
{
  "status_code": 200,
  "total_results": 2,
  "blogs": [
    {
      "id": 1,
      "title": "Understanding AI",
      "author_id": 123,
      "published_at": "2024-02-10T14:00:00Z",
      "tags": ["AI", "Tech"],
      "excerpt": "A deep dive into artificial intelligence..."
    },
    {
      "id": 2,
      "title": "Machine Learning Basics",
      "author_id": 123,
      "published_at": "2024-01-25T10:15:00Z",
      "tags": ["ML", "AI"],
      "excerpt": "Breaking down the core principles of machine learning..."
    }
  ]
}

No Blog Posts Found

{
  "status_code": 200,
  "total_results": 0,
  "blogs": []
}

Server Error

{
  "status_code": 500,
  "message": "An unexpected error occurred."
}

Testing

  • Write unit tests for valid author_id queries.
  • Test for cases where no blog posts exist.
  • Ensure pagination is working correctly.
  • Validate response structure and performance.
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

No branches or pull requests

1 participant