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]: GET /api/v1/blogs/{blog_id}/engagement #1173

Closed

Conversation

0x00whitecode
Copy link

@0x00whitecode 0x00whitecode commented Mar 1, 2025

Description

This PR introduces an API endpoint to fetch engagement metrics for a specific blog post. The endpoint provides insights into a post’s popularity by tracking views, likes, comments, and shares.

Key Changes

  • Implemented GET /api/v1/blogs/{blog_id}/engagement to retrieve engagement data.
  • Tracks and returns:
    • Total Views
    • Total Likes
    • Total Comments
    • Shares (if applicable)
  • Optimized view tracking to avoid real-time database writes:
    • Uses Redis for temporary view storage.
    • Batches updates to the database periodically.
  • Efficient counting strategies for likes and comments:
    • SQL: Uses COUNT(*) on indexed columns.
    • NoSQL (MongoDB): Stores engagement metrics in a separate collection for performance optimization.

API Response Example

{
  "blog_id": "123",
  "views": 2450,
  "likes": 150,
  "comments": 25,
  "shares": 10
}

Related Issue

#ISSUE1136

Motivation and Context

This feature enables blog authors and administrators to monitor engagement metrics, assess a post’s popularity, and support recommendation systems by identifying high-engagement content.

How Has This Been Tested?

✔️ Unit tests using pytest to verify:
✅ Successful retrieval of engagement data (200).
✅ Handling of non-existent blog posts (404).
✅ Efficient database read operations.
✔️ Mocked Redis caching and batch database updates using unittest.mock.MagicMock.

Screenshots (if applicable)

📊 Engagement metrics retrieved for a blog post.

Types of Changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link
Contributor

@samuelogboye samuelogboye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants