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] : Allow users schedule blog posts for future publication #1169

Open
KehindeBello opened this issue Feb 28, 2025 · 2 comments
Open

[FEAT] : Allow users schedule blog posts for future publication #1169

KehindeBello opened this issue Feb 28, 2025 · 2 comments
Labels

Comments

@KehindeBello
Copy link

KehindeBello commented Feb 28, 2025

Description
Enhance the existing blog post creation endpoint to allow users to schedule posts for future publication.

Requirements

  • Modify the existing POST /api/v1/blogs endpoint to handle scheduled posts.
  • Ensure the endpoint remains secured and accessible only to authorized users.
  • Store scheduled posts in the database with a pending status.
  • Modify the database schema to support a scheduled_at field and status field (published or pending).
  • Provide a database migration file to add the necessary columns to the blogs table.
  • Implement a background job to check and publish scheduled posts at the correct time.
  • Modify the GET /api/v1/blogs endpoint to return only published posts, excluding scheduled ones.
  • Ensure proper error handling for:
    • Unauthorized access
    • Invalid scheduling time
    • Blog post scheduling failures
  • Write comprehensive unit tests to validate both immediate publishing and scheduling.

Example Request

Request Type: POST
Request URL: /api/v1/blogs

Headers:

Authorization: Bearer <your_access_token>  
Content-Type: application/json

Payload for immediate publishing:

{
  "title": "string",
  "content": "string",
  "image_url": "string",
  "tags": [
    "string"
  ],
  "excerpt": "string"
}

Payload for scheduled publishing:

{
  "title": "string",
  "content": "string",
  "image_url": "string",
  "tags": [
    "string"
  ],
  "excerpt": "string",
  "scheduled_at": "DDDD-MM-DDT00:00:00Z"
}

Response [Success]

For immediate publishing:

{
  "status": "success"
  "status_code": 201,
  "message": "Your blog post has been published successfully.",
  "data": {}
}

For scheduled publishing:

{
  "status": "success"
  "status_code": 201,
  "message": "Your blog post has been scheduled successfully.",
  "data": {}
}

Response [Errors]

Unauthorized Request

{  
  "status": "error"
  "status_code": 401,
  "message": "Not authenticated."
  "data": {}
}

Invalid Scheduling Time

{
  "status": "error"
  "status_code": 400,
  "message": "Scheduled time must be in the future."
  "data": {}
}

Scheduling Failure

{
  "status": "error"
  "status_code": 500,
  "message": "Failed to schedule blog post."
  "data": {}
}

Testing

  • Write unit tests to validate both immediate publishing and scheduling.
  • Test proper authentication and authorization mechanisms.
  • Verify scheduled posts are correctly stored and published at the right time.
  • Test that cases such as scheduling in the past result in 400
@KehindeBello
Copy link
Author

@Takinnuoye5

@KehindeBello
Copy link
Author

KehindeBello commented Feb 28, 2025

@joboy-dev I've formatted the response correctly. Kindly approve.

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

No branches or pull requests

2 participants