Skip to content

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

@idehen-divine

Description

@idehen-divine

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions