/ratetask

Primary LanguagePython

Average rate API

Average rate calculation API. API will return the response from the date_from to date_to for given origin and destination
Requirement is to use sql query only in place of ORM. So that sql has been written to get data from database tables.
There are three tables
  1. PORTS
  2. REGIONS
  3. PRICES

Required columns you can know from sql queries.

Steps for run

1) clone repository
2) change DATABASE_URL value as per your environment

  DATABASE_URL variable exist in .env file as below
DATABASE_URL=postgresql://postgres:ratetask@localhost:5432/postgres
 Here example is for localhost means postgres is installed on local machine
 There will be user postgres , password in ratetask and database name is postgres
3) install virtual environment ( if not install )
  pip install virtualenv
4) create virtual environment from below command
 python -m venv venv
5) Activate virtual environment from below command in command prompt
  . venv\Scripts\activate.bat
In Windows below command will be used for activate virtual env
  venv\Scripts\activate.bat
6) install required package using below command
  pip install -r requirement.txt
7) to run app execute below command in command prompt
  flask run
  if getting below line then your environment is working fine
  * Running on http://127.0.0.1:5000
To deactivate virtual environment use below command
  venv\Scripts\deactivate.bat

API endpoint


POST http://127.0.0.1:5000/rates?date_from=date_from&date_to=date_to&origin=origin&destination=destination
* query param values - date_from, date_to, origin, destination
* date format should be: YYYY-MM-DD
* origin/destination should have PORT code or region slug

Response


[ { "day": "YYYY-MM-DD", "average_price": "average_price" }, { "day": "YYYY-MM-DD", "average_price": "null" }, ... ... ]

Error Response


 1. If origin/ destination is empty
 GET (http://127.0.0.1:5000/rates?date_from=2016-01-01&date_to=2016-01-10&origin=CNSGH&destination=)

  Response is as - image

 2. If date_from/date_to are not valid
 GET (http://127.0.0.1:5000/rates?date_from=2016-01-32&date_to=2016-01-10&origin=CNSGH&destination=north_europe_main)

  Response is as - image

 3. If DATABASE_URL have incorrect password or configuration is not present or db connection not established
  Change DATABASE_URL for test as - image


  GET (http://127.0.0.1:5000/rates?date_from=2016-01-01&date_to=2016-01-10&origin=CNSGH&destination=north_europe_main)

  Response is as - image

Contact


  For any query please email on : ajayawasthimca@gmail.com