Skip to content

Implement Authenticated Product Review Submission Endpoint - #16

Open
HermanL0201 wants to merge 7 commits into
199358a8-4bbc-457d-bb74-b89ae5096bb7from
feature-submit-product-review-endpoint-1749180729
Open

Implement Authenticated Product Review Submission Endpoint#16
HermanL0201 wants to merge 7 commits into
199358a8-4bbc-457d-bb74-b89ae5096bb7from
feature-submit-product-review-endpoint-1749180729

Conversation

@HermanL0201

@HermanL0201 HermanL0201 commented Jun 6, 2025

Copy link
Copy Markdown
Owner

Implement Authenticated Product Review Submission Endpoint

Description

Task

Create an authenticated route for users to submit product reviews

Acceptance Criteria

  • Endpoint requires authentication
  • Validates product ID and rating
  • Prevents multiple reviews per product
  • Supports optional comment
  • Returns 201 on successful review submission
  • Returns appropriate error messages for invalid inputs

Summary of Work

This pull request adds a robust and secure endpoint for submitting product reviews with comprehensive validation and error handling.

Key Implementation Details:

  • Created a POST /reviews endpoint for submitting product reviews
  • Implemented authentication middleware to ensure only logged-in users can submit reviews
  • Added input validation for review submission:
    • Requires productId and rating
    • Rating must be between 1 and 5
    • Prevents multiple reviews of the same product by a user
  • Stores reviews with user ID, product ID, rating, optional comment, and timestamp
  • Provides informative error messages for various validation scenarios

Validation Checks:

  • Authenticates user via authMiddleware
  • Validates required fields (productId, rating)
  • Ensures rating is within 1-5 range
  • Checks for existing reviews to prevent duplicates
  • Limits comment length to 500 characters

Error Handling:

  • Returns 400 for validation errors
  • Returns 500 for server-side errors
  • Logs server errors for debugging
  • Provides clear error messages to client

Changes Made

  • Created POST endpoint for product reviews in src/routes/reviewRoutes.ts
  • Implemented input validation for review submission
  • Added duplicate review prevention
  • Created comprehensive error handling
  • Integrated with existing Review model in src/models/Review.ts

Tests

  • Verify authenticated users can submit reviews
  • Validate rating range (1-5)
  • Prevent duplicate product reviews
  • Check required field validation
  • Validate comment length limit
  • Test server error handling

Signatures

Staking Key

DZwmqbbKALnQYMhTLYdYeBBKVNptDMSAKQjaASJ9btgo: 26h8BmXLb4nm6HUrSNgeAyRCYHUfeUKA4fJfFPfx1EqjeUyi8XP29tqu4hTQso35jsSk5ofzJZg8Eitk2GQLRbRUabW6S5hGcDQ7KiYQkTGM83Zb11k39hyGJ5zgW9Bu774vEcz66SycTYpFrko1JNTvmPXpmuSH6DvgUK1zmsTYpX57DiPLevdM4AAuXfWdyz84wMZwNQRT37qtDtYMaRJteXGaNXFHC3M8eZm2cX2jG4roUo6dmdFYSH1rK43tKiVc5qcyPHdaim8CeU88e3ff1WTF46Wzivah6FhMhwX2bXF13excuAYiwEPvmRBBRr21vFrRcVhH1ddQdV2msaQAMbwyc7UvpGW9NWVSVJzFqbN9LZs16NDmdvbjTpyS77YFMLLgfKQwVgdHvPuCyhjbiRS5yfgpKMJt

Public Key

4E3nQUGBiknkTFLJE6Htj3KKNnHzpxhNv2Jw5cvW4s7J: DEcHA2AEGHuBtntEb6zTnr3qZPZAGWtHHwDRZSXeZjFEXVffo1kkkbymnHyzCMFGgy7V5YKsmY8Ea3dc1vw78CLYbNe2GK3iJnTZ89xf8ww6SFyLB21SFGbYhwftjH3vk9nDy1oAxEfBfudWUw2kSLCUENSxeU92Aj27umL4jNa7rTcekqfATkYGtSsGTFD37FqAr64dzdCrj9TCbSH1ae1QCgLhNHE9ToWthdiXojWaYoYenPPU8iJeVsnsCoWyd34gfW81sNhDK39BxUcrdn8e5isTukiA9UNFugYG1pobg3dqEkQ7C9eSvkLWixVQdM9nQucyY3HT8Z2EWHwtca5hQTLHKE7qnGPkeceYgtCGnpwBAkQwKFWPycv8M1aDysPqW2EWNx2ATvKBXybBuuTrGSR1aTnRqS4

@HermanL0201 HermanL0201 changed the title [WIP] Implement Product Review Submission Endpoint Implement Authenticated Product Review Submission Endpoint Jun 6, 2025
@HermanL0201
HermanL0201 marked this pull request as ready for review June 6, 2025 03:36
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.

1 participant