Pythonian / fastapi_web

Building a FastAPI application.
MIT License
0 stars 0 forks source link

Blog Update API Endpoint #5

Open Pythonian opened 2 months ago

Pythonian commented 2 months ago

Description

Develop an endpoint to handle requests to update an existing blog post. This endpoint will validate the input data and update the blog post securely in the database. This endpoint should be accessible only to super admins. If the blog post is updated successfully, it will be returned to the client with a 200 OK status. If an error occurs, an appropriate error status will be returned.

Acceptance Criteria

Purpose

Provide the necessary backend services to allow super admin to edit and update their previously published blog posts.

Requirements

Expected Outcome

Endpoints

[PATCH] /api/v1/blogs/:id

Testing

Test Scenarios

  1. Successful Update of Blog Post

    • Ensure that the endpoint successfully updates the data of an existing blog post.
    • Verify that the response includes the updated blog post data and a 200 OK status code.
  2. Unauthorized Access

    • Simulate a request from a non-super admin user or from an unauthenticated user.
    • Confirm that the endpoint returns a 403 Forbidden status code and an appropriate error message.
  3. Conflict Error

    • Simulate a request to update a blog post with a title that already exists.
    • Verify that the endpoint returns a 409 Conflict status code and an appropriate error message.
  4. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code and an appropriate error message.
  5. Blog Post Not Found

    • Simulate a request to update a blog post that does not exist.
    • Confirm that the endpoint returns a 404 Not Found status code and an appropriate error message.
  6. Invalid Data

    • Send requests with invalid data (e.g., missing required fields, incorrect data types).
    • Verify that the endpoint returns a 400 Bad Request status code and an appropriate error message.
Pythonian commented 2 months ago
{
  "status_code": 200
  "message": "Blog post updated successfully",
  "data": {
    "id": "7d1f89c2-3c24-7c3f-a8e5-9a8a3e6d2f7b",
    "title": "Updated Title",
    "content": "Updated content",
    "author_id": "a7f6e0c1-52e5-4d30-8b27-f2be4d4d1c77"
  }
}

I think the response body should incorporate some of the structure above.

{
  "message": "Blog successfully updated",
  "id": "int",
  "title": "string",
  "excerpt": "string",
  "content": "string",
  "author": "string",
  "updated_at": "datetime",
}