hngprojects / hng_boilerplate_golang_web

Apache License 2.0
77 stars 49 forks source link

[FEAT] API Endpoint to create a Testimonial #297

Open Iretoms opened 1 month ago

Iretoms commented 1 month ago

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

Create Testimonial

Successful Response

Endpoint

[POST] /api/v1/testimonials

Requests

POST /api/v1/testimonials

{
  "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

Expected Outcome

Testing

Unit Tests:

Authorization Tests:

Validation Tests: