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] API Endpoint to create a Testimonial #297

Open
Iretoms opened this issue Aug 7, 2024 · 0 comments
Open

[FEAT] API Endpoint to create a Testimonial #297

Iretoms opened this issue Aug 7, 2024 · 0 comments

Comments

@Iretoms
Copy link
Contributor

Iretoms commented Aug 7, 2024

Description

Implement a protected API endpoint that allows authenticated users to create a new testimonial. Ensure the endpoint handles validation errors properly and returns the created testimonial along with appropriate status codes.

Acceptance Criteria

Authentication

  • The endpoint should be protected and require the user to be authenticated.
  • If the user is not authenticated, the endpoint should return a 401 Unauthorized status with an appropriate error message.

Create Testimonial

  • The endpoint should allow authenticated users to create a new testimonial.
  • The testimonial submission should include necessary fields like “name” and "content".

Successful Response

  • If successful, it should return a 200 OK status code.
  • The response should include the created testimonial.

Endpoint

[POST] /api/v1/testimonials

Requests

POST /api/v1/testimonials

  • Content-Type: application/json
  • Authorization: Bearer <access_token>
{
  "name": "Charles Ugberaese",
  "content": "The service is fantastic, great experience."
}

Successful Response

{
  "status": "success",
  "message": "Testimonial created successfully",
  "data": {
    "user_id": "0b89cd08-57fc-40b0-aa17-ed6d95f43cfe",
    "name": "Charles Ugberaese",
    "content": "The service is fantastic, great experience.",
    "created_at": "2024-07-18"
  }
}

Error Response

401 Unauthorized

{
  "status": "Unauthorized",
  "message": "Unauthorized. Please log in.",
  "status_code": 401
}

Error Response

400 Bad Request

{
  "status": "Bad Request",
  "message": "Please check the submitted data",
  "status_code": 400
}

Error Response

500 Internal Server Error

{
  "status": "Internal Server Error",
  "message": "Internal Server Error. Please try again later.",
  "status_code": 500
}

Purpose

Allow authenticated users to submit and create new testimonials and ensure that the submitted data is stored accurately in the database.

Requirements

  • Endpoint is protected and requires user authentication.
  • Endpoint allows submission of new testimonials with required fields.
  • Testimonial objects returned contain necessary fields.
  • Endpoint returns proper error messages for validation errors, unauthorized access, and internal server errors.

Expected Outcome

  • Authenticated users should be able to submit new testimonials, which are then stored in the database.
  • Successful submissions should return the created testimonial with the necessary fields.
  • Unauthenticated users should receive an HTTP 401 Unauthorized error.
  • Proper error handling ensures the security and reliability of the endpoint.

Testing

Unit Tests:

  • Write unit tests to ensure the endpoint correctly creates a testimonial.

Authorization Tests:

  • Test that the endpoint returns 401 Unauthorized when the request is made by an unauthenticated user.
  • Test that the endpoint allows access to authenticated users only.

Validation Tests:

  • Ensure the endpoint returns appropriate validation errors for missing or invalid data.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant