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: add testimonial update endpoint #1216

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from

Conversation

Samuelhetty
Copy link

Description

This pull request introduces a new API endpoint that allows users to update their testimonials. It enhances the testimonial system by allowing users to update their own testimonials securely while maintaining a structured response

New Endpoint

🔹 Method: PUT /api/v1/testimonials/{id}
🔹 Description: Allows users to update testimonials they created.
🔹 Authorization: Only the testimonial's owner can update it.

Example Request:

{
  "content": "This is the updated testimonial."
}

Example Success Response:

{
  "status_code": 200,
  "success": true,
  "message": "Testimonial updated successfully",
  "data": {
    "id": "067c2323-d10e-7884-8000-fb8b216581d0",
    "content": "This is the updated testimonial.",
    "user_id": "12345",
    "created_at": "2025-02-28T12:34:56"
  }
}

Example Failure Response (Unauthorized User):

{
  "status_code": 403,
  "success": false,
  "message": "You are not allowed to update this testimonial."
}

Link to Issue

Closes [#776] (#776)

Motivation and Context

✔️ Enables users to modify testimonials they previously created.
✔️ Ensures only authorized users can update their own testimonials.
✔️ Provides a structured and consistent API response.

Changes Implemented

🔹 Added the PUT /api/v1/testimonials/{id} endpoint.
🔹 Implemented logic to restrict updates to the testimonial's creator.
🔹 Standardized the API response to return the updated testimonial.
🔹 Wrote unit tests to verify success and failure scenarios.

How Has This Been Tested?

✔️ Unit Tests:

Tested successful updates for authorized users.
Tested failure responses for unauthorized users.
✔️ Manual Testing:

Verified the endpoint using Postman with valid and invalid users.
✔️ Automated Tests:

Ran pytest to confirm all tests pass.

Files Updated

📂 api/v1/routes/testimonials.py
📂 api/v1/services/testimonial_service.py
📂 tests/v1/testimonial/test_testimonial_updates.py

Screenshots (if appropriate - Postman, etc):

Created Testimonial Response
Updated Testimonial Response

Types of changes

[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

[x] My code follows the code style of this project.
[x] My change requires a change to the documentation.
[x] I have updated the documentation accordingly.
[x] I have read the CONTRIBUTING document.
[x] I have added tests to cover my changes.
[x] All new and existing tests passed.

@Samuelhetty Samuelhetty changed the title [FEAT]: Add Testimonial Update Endpoint feat: Add Testimonial Update Endpoint Mar 2, 2025
@Samuelhetty Samuelhetty changed the title feat: Add Testimonial Update Endpoint feat: add testimonial update endpoint Mar 2, 2025
Copy link
Contributor

@joboy-dev joboy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is your virtual environment here??
Please remove

alembic.ini Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this back to the way it was

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! please review

Copy link
Author

@Samuelhetty Samuelhetty Mar 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry about that. It's off now. Thank You

@Samuelhetty
Copy link
Author

On it boss

@joboy-dev
Copy link
Contributor

You want me to merge your virtual environment too??

user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False)
user_id = Column(String, ForeignKey("users.id"), nullable=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you touch this line of code?

How is it related to your issue?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It gave some errors while testing and a mentor said i could adjust it. Reverted back now.

Comment on lines 48 to 50
db.commit()
db.refresh(testimonial)
return testimonial
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move line 48-50 outside the loop

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done that now

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

Successfully merging this pull request may close these issues.

3 participants