feat: add testimonial update endpoint#1216
Open
Samuelhetty wants to merge 16 commits intohngprojects:devfrom
Open
feat: add testimonial update endpoint#1216Samuelhetty wants to merge 16 commits intohngprojects:devfrom
Samuelhetty wants to merge 16 commits intohngprojects:devfrom
Conversation
Signed-off-by: Henrietta Onoge <125442361+Samuelhetty@users.noreply.github.com>
joboy-dev
requested changes
Mar 2, 2025
Contributor
There was a problem hiding this comment.
Revert this back to the way it was
Author
There was a problem hiding this comment.
I'm sorry about that. It's off now. Thank You
Author
|
On it boss |
Contributor
|
You want me to merge your virtual environment too?? |
samuelogboye
requested changes
Mar 2, 2025
api/v1/models/activity_logs.py
Outdated
| __tablename__ = "activity_logs" | ||
|
|
||
| user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False) | ||
| user_id = Column(String, ForeignKey("users.id"), nullable=False) |
Contributor
There was a problem hiding this comment.
Why did you touch this line of code?
How is it related to your issue?
Author
There was a problem hiding this comment.
It gave some errors while testing and a mentor said i could adjust it. Reverted back now.
api/v1/services/testimonial.py
Outdated
Comment on lines
48
to
50
| db.commit() | ||
| db.refresh(testimonial) | ||
| return testimonial |
Contributor
There was a problem hiding this comment.
Move line 48-50 outside the loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
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.