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]: Enpoint for updating testimonal by ID (Authenticated users only) #1154

Open
5 tasks
edenis00 opened this issue Feb 28, 2025 · 0 comments
Open
5 tasks

Comments

@edenis00
Copy link

edenis00 commented Feb 28, 2025

Description

Create an endpoint that allows authenticated users to update user testimonials, ensuring accurate and up-to-date feedback on the platform.

Acceptance Criteria

  • It should be an authenticated endpoint, accessible only to authenticated users.
  • It should be a PUT request at `/api/v1/testimonials/{testimonial_id}.
  • The system should update the testimonial content in the database.
  • The response should return a structured JSON format with a status code 200 upon successful update..
  • If the testimonial does not exist, the request should return an appropriate error message.
  • If the requesting user is unauthorized, the request should return an authentication error message.

Purpose

To allow authenticated users to edit and update testimonials, ensuring they remain relevant well-formatted, and properly moderated.

Requirements

  • The server-side logic to update a testimonial specified by the testimonial_id in the database.
  • Ensure the endpoint is secured and accessible only to authenticated users.
  • Write unit tests to validate the functionality of the endpoint.

Expected Outcome

Authenticated should be able to update testimonials while ensuring proper authorization, content moderation and record tracking.

Tasks

  • Create an endpoint PUT:/api/v1/testimonals/{testimonial_id} to update a testimonial.
  • Implement authentication and authorization to restrict access to authenticated only.
  • Develop logic to update the testimonial content in the database.
  • Ensure proper error handling for:
  • Unauthorized access
  • Testimonal not found
  • Write comprehensive unit tests for the endpoint.

Example Request

  1. Open Postman
  2. Set the Request Type to PUT
  3. Enter the Request URL:
/api/v1/testimonials/{testimonials_id}
  1. Then go to the "headers" tab
    • Add a key: Authorization
    • Value: Bearer <your_access_token>
    • Add another key: Content-Type
    • Valie: application/json
  2. Go to the "Body" Tab
    • Select raw and chose JSON as the format
    • paste this JSON payload:
     {
      "content": "This is an updated testimonials."
      }

Response [Success]

{
  "status_code": 200,
  "mesage": "Your testimonial has been updated successfully.",
  "data": "user_data"
}

Response [Errors]

Unauthorized Request

{
  "status_code": 403,
  "mesage": "Forbidden. Admin access required."
}

Testimonial Not Found

{
  "status_code": 404,
  "mesage": "Testimonial not found."
}

Testing

  • Write unit tests to ensure the endpoint works as expected.
  • Test proper authentication and authorization mechanisms.
  • Test edge cases, such as updating a unauthorized access attempts.
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