Open
Description
Description
Create an API endpoint to allow super admin handle editing existing blog posts. This endpoint will validate the input data and update the blog post securely in the database
Acceptance Criteria
- The endpoint allows only a super admin to edit an existing blog post.
- The endpoint should be accessible at
/api/v1/blog/edit/{blog_id}
- The endpoint should accept HTTP PUT requests.
- The API should validate the request payload to ensure the title and other necessary fields is provided.
- Upon successful validation of the input data, the blog post should be updated in the database securely.
- Return a 200 OK status code on successful request.
Request body application/json
{
"title": "string",
"excerpt": "string",
"tags": ["string"]
}
Success payload
{
"message": "Blog successfully updated",
"id": "int",
"title": "string",
"excerpt": "string",
"updated_at": "Datatime"
}
Error payload
{
"message": "Unauthorized request",
"status_code": 401
}
Purpose
Provide the necessary backend services to allow super admin to edit and update their previously published blog posts.
Requirements
- Implement server-side logic to handle blog post edit submissions.
- Validate and sanitize incoming data.
- Update the blog post securely in the database.
- A 401 error should be sent if an unauthorized user tries to edit a blog
Expected Outcome
The API endpoint allows super admin to edit their blog posts via the provided data, ensuring all updates are securely stored and validated.
Test
- Write unit tests to ensure the blog post edit endpoint validates input correctly and updates the post securely.
- Test various scenarios for editing blog posts (e.g., missing title, empty content, invalid tags).
- Perform security test to ensure unauthorized user can not update a blog post.
- Test various scenarios:
- Successful editing of an existing blog post
- Attempting to edit a non existing blog post
- Attempting to edit a blog post without authentication
- Attempting to edit a blog post without proper permissions