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.
Pull Request
Title
Renting APIs for products
Description
Renting Agricultural Equipment
Endpoint: POST /rentals
Updating Rental Details
Endpoint: PUT /rentals/{rentalId}
Cancelling a Rental
Endpoint: DELETE /rentals/{rentalId}
Viewing Rental Details
Endpoint: GET /rentals/{rentalId}
Returning Rented Equipment
Endpoint: POST /rentals/{rentalId}/return
Related Issues
fixes #882
Changes Made
RentProduct Schema:
Added rental price fields for different durations: rentalPricePerHour, rentalPricePerDay, rentalPricePerWeek, rentalPricePerMonth.
Introduced availabilityStatus to track product rental status ('available', 'rented', 'maintenance').
Included rentedQuantity to track how many items of the product have been rented.
User Schema:
Rentals array stores rental data with rentalId, product, quantity, rentalDuration, and rental status.
Rental Controller:
Implemented logic to check product availability using availabilityStatus before proceeding with rental creation.
Added dynamic rental price calculation based on rentalDuration and corresponding product price.
Improved error handling for missing rental prices depending on the duration type.
Added logging for better debugging (e.g., logging product availability status).
Managed the update of rented quantity and availability status of the product upon successful rental creation.
Checklist
Screenshots (if applicable)