-
Notifications
You must be signed in to change notification settings - Fork 218
Open
Labels
Description
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 (
publishedorpending). - 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