Skip to content

RentalTooService ‐ Checkout a tool for rent

Dennis Chacko edited this page Jul 18, 2024 · 16 revisions

Checkout a tool for rent

Table of Contents

Overview

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 the final price
  • Saves the rental request
  • Creates and saves the rental agreement

Sample Request/Response

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
}

Sequence diagram

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

Loading

Exception

The operation throws a ValidationException if called with an invalid tool code

Clone this wiki locally