-
Notifications
You must be signed in to change notification settings - Fork 0
RentalTooService ‐ Checkout a tool for rent
Dennis Chacko edited this page Jul 26, 2024
·
16 revisions
Table of Contents |
---|
The Checkout a tool for rental creates a Rental Agreement for the requested checkout date. As part of this functionality, the operation
- Checks if the tool requested for checkout is a valid tool
- Calculates the rental days and if those days are weekdays, weekends or observed holidays
- Checks if the tool requested for checkout is available for the requested days
- Calculates the
pre-discount
price,the discount
if requested, and thefinal price
- Saves the rental request
- Creates and saves the rental agreement
Request to checkout and create a rental agreement
The below curl command can be used to checkout and create a rental agreement
curl --location --globoff '{{baseUrl}}/api/v1/tool/CHNS/checkout' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --data '{ "checkout_date": "01/12/2024", "rental_days_count": "10", "tool_code": "CHNS", "discount_percent": "10" }'
{
"checkout_date": "01/12/2024",
"rental_days_count": "10",
"tool_code": "CHNS",
"discount_percent": "10"
}
Sample Response to checkout and create a rental agreement
The service should respond back with the below json
{
"tool_code": "CHNS",
"tool_type": "Chainsaw",
"tool_brand": "Stihl",
"rental_days": "10",
"checkout_date": "01/12/2024",
"due_date": "01/22/2024",
"daily_charge": 2.99,
"charge_days": 7,
"pre_discount_charge": 20.93,
"discount_percent": "10%",
"discount_amount": 2.09,
"final_charge": 18.84
}
sequenceDiagram
AbstractController->>+RentalAgreementService: Create Rental Agreement for tool code
RentalAgreementService->>+ToolPriceRepository: Fetch pricing details for tool code
ToolPriceRepository-->>-RentalAgreementService: pricing details
alt invalid tool code
RentalAgreementService->>ToolPriceRepository: Fetch pricing details for tool code
ToolPriceRepository->>RentalAgreementService: Tool code not found
RentalAgreementService ->> RentalAgreementService: Throw ValidationException
end
RentalAgreementService-->>+RentalDurationService: Calculate Rental Dates
RentalDurationService-->>-RentalAgreementService: Rental dates
RentalAgreementService->>RentalAgreementService: Is tool available for Rental?
alt Tool is unavailable
RentalAgreementService ->> RentalAgreementService: Throw ValidationException
end
RentalAgreementService->>+RentalRequestRepository: Create and save rental request
RentalRequestRepository-->>-RentalAgreementService: Rental Request
RentalAgreementService->>RentalAgreementService: calculate Rental price with discounts
RentalAgreementService->>+RentalAgreementRepository: Creat and Save Rental Agreement
RentalAgreementRepository->>-RentalAgreementService: Rental Agreement
RentalAgreementService-->>-AbstractController: Rental Agreement
The service responds with the below error codes for invalid inputs. These error codes are wrapped in a ValidationException
Error Condition | Response Code and Desciption |
---|---|
Unknown Tool Code | Http 400 Bad Request Invalid tool code |
Invalid or missing checkout date | Http 400 Bad Request Invalid or missing checkout date |
Invalid discount percent | Http 400 Bad Request Invalid discount %. Please enter a value between 0-100 |