Skip to content

An Experimental application in goLang to work in a simple pricing engine considering various factors from the customer who is trying to rent a vehicle from a rental service provider.

Notifications You must be signed in to change notification settings

rajagopal28/pricing-engine-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pricing Engine - GoLang

Application in goLang to work in a simple pricing engine considering various factors from the customer who is trying to rent a vehicle from a rental service provider.

Requirements

The requirement of this application is to bring up a go based REST API which will determine the rental cost of a car bases on the attributes of the customer who is purchasing it. You can go through the detailed requirements Here. The essential attributes that play key aspects in the pricing calculation are as follows:

  • Rent Duration
  • Age of the customer
  • Insurance Group
  • Validity of the licence held by the customer

The Pricing formula

Total Rental Cost = BaseFare based on the Duration * Factor based on Age * Factor based on the Insurance Group * Factor based on Licence Validity

Understanding the existing setup

The current application is built on top on an existing code as per the Requirements. The setup typically had a layered data flow among the components as follows:

  • The main.go file which typically invoked the service.
  • The service that serves various REST end point for the application and passing on the data to RPC layer.
  • The RPC which typically takes care of doing the conversion from HTTP middleware understandable data to the Application understandable data.
  • Then the RPC passes the application understandable data to the App component which has all the business logics of computing the pricing and serving the required data.

The Approach in solving the problem

The Flow

The Endpoints

Generate Pricing for a customer

Add a new transaction

Request
POST /generate_pricing HTTP/1.1
Host: localhost:3000
Content-Type: application/json

{
    "date_of_birth": "1970-12-04",
    "insurance_group": 12,
    "license_held_since": "1988-08-01"
}

Request format:

date_of_birth – Date of Birth of the customer who is trying to rent the vehicle insurance_group – the insurance group to which the customer belongs to license_held_since – The date of acquiring of the Driver's licence by the existing customer

Response

Returns: Empty body with one of the following:

200 – in case of success

HTTP/1.1 200 OK
Content-Type: application/json
{
  "input": {
          "date_of_birth": "1970-12-04",
          "insurance_group": 12,
          "license_held_since": "1988-08-01"
      },
      "is-eligible": true,
      "message": "Success",
      "pricing": [
          {
              "premium": 278.28254999999996,
              "currency": "£",
              "fare_group": "0.5 hours, Driver Age >26, Insurance Group:9-16, Licence Validity:6"
          },
          {....},
          {....},
          .....
      ]
}

Get current pricing configuration ranges

Request
GET /statistics HTTP/1.1
Host: localhost:3000

Response

Returns: The computed statistics for all the posted transaction or empty if there are no transactions present.

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
{
  "base-rate": [
        {
            "Start": 0,
            "End": 1800,
            "IsEligible": true,
            "Value": 273,
            "Label": "0.5 hours"
        },
        {....}
        ....
        ],
    "driver-age-factor": [
        {
            "Start": 0,
            "End": 16,
            "IsEligible": false,
            "Value": 0,
            "Label": "Driver Age:0-16"
        },
        {...}
        ....
      ],
      "insurance-group-factor": [
          {
              "Start": 1,
              "End": 8,
              "IsEligible": true,
              "Value": 1,
              "Label": "Insurance Group:1-8"
          },
          {...},
          ....
      ],
      "licence-validity-factor": [
        {
            "Start": 0,
            "End": 1,
            "IsEligible": true,
            "Value": 1.1,
            "Label": "Licence Validity:0-1"
        },
        {...}
        .....
      ]
    }

Setting up the environment

This application is purely build on goLang. To run this application in your local you need to follow the below steps

Build:

go build ./cmd/.

Run

go run ./cmd/.

Test

go test ./test/.

References:

About

An Experimental application in goLang to work in a simple pricing engine considering various factors from the customer who is trying to rent a vehicle from a rental service provider.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages