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

Blog Create API Endpoint #1

Open
4 tasks
Pythonian opened this issue Jul 20, 2024 · 0 comments
Open
4 tasks

Blog Create API Endpoint #1

Pythonian opened this issue Jul 20, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Pythonian
Copy link
Owner

Pythonian commented Jul 20, 2024

Description

Develop an endpoint to handle requests to create a new blog post. If the blog post is created successfully, it will be returned to the client with a 201 Created status. If an error occurs, an appropriate error status will be returned.

Blog Table Schema

Field Type Description Constraints
id Integer Unique identifier for the blog post Primary Key, Auto Increment
title String Title of the blog post Unique, Not Null, Max Length: 255
excerpt String A summary of the blog post Max Length: 300, Not Null
content Text Full content of the blog post Not Null
image_url String A url string of the image Max Length: 255, Not Null
is_deleted Boolean Flag for soft deletion of the blog post Default: False
created_at DateTime Timestamp when the blog post was created Default: Current Timestamp
updated_at DateTime Timestamp when the blog post was last updated Default: Current Timestamp, Updated on Modification

Acceptance Criteria

  • The endpoint allows creating a new blog post with the fields: title, excerpt, image_url and content.
  • The endpoint validates the input data and returns appropriate error messages for invalid data or missing required fields.
  • Returns a 201 Created status code and the created blog post data when the blog post is created successfully.

Requirements

  • Implement API endpoint for creating a new blog post.
  • Validate the input data, including length and format checks for title, excerpt, image_url and content.
  • Handle conflicts if a blog post with the same title already exists and return a 409 Conflict status code.
  • Handle unexpected errors and return the appropriate status code.

Expected Outcome

  • Users should be able to send a request to create a new blog post.
  • Users should receive appropriate status codes and responses based on the outcome of the request.

Endpoints

[POST] /api/v1/blogs

  • Description: Creates a new blog post.

  • Request Body (JSON):

     {
       "title": "New Blog Post",
       "excerpt": "A summary of the blog post...",
       "content": "The content of the blog post...",
     }
  • Success Response:

    • Status: 201 Created

    • Body:

      {
        "id": 1,
        "title": "New Blog Post",
        "excerpt": "A summary of the blog post...",
        "content": "The content of the blog post...",
        "image_url": "image-url-link",
        "created_at": "2024-07-18T00:00:00Z",
        "updated_at": "2024-07-18T00:00:00Z"
      }
  • Error Response:

    • Status: 500 Internal Server Error

    • Body:

      {
          "error": "Internal server error."
      }
  • Conflict Response:

    • Status: 409 Error: Conflict

    • Body:

      {
          "detail": "A blog post with this title already exists."
      }
  • Validation Error Response:

    • Status: 422 Error: Unprocessable Entity

    • Body:

      {
          "detail": "Invalid data message."
      }

Testing

Test Scenarios

  1. Successful Creation of Blog Post

    • Ensure that the endpoint successfully creates a new blog post.
    • Verify that the response includes the created blog post data and a 201 Created status code.
  2. Conflict Error

    • Simulate a request to create a blog post with a title that already exists.
    • Verify that the endpoint returns a 409 Conflict status code and an appropriate error message.
  3. 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.
  4. 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.
  5. Boundary Testing for Fields

    • Test the maximum length constraints for the title and excerpt fields.
    • Ensure that the endpoint handles the boundary conditions correctly and returns appropriate error messages for exceeding the length limits.
@Pythonian Pythonian self-assigned this Jul 22, 2024
@Pythonian Pythonian added the enhancement New feature or request label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant