Machine setup for API Implementation.
API: Find In Store API
Description: Allows finding inventory of items in nearby stores. This application contains two components
-
API implementation: Find location(lat,lng) using Google Geocode API for the provided address. And then uses this location(lat,lng) to lookup nearby stores in database table stored in db. And then lookup inventory for the items in the request for these nearby stores (limited to 5) and respond back with result.
-
Supporting Integration: This integration
- Is used to load inventory in storeitemqty table. This can be setup as full sync once a day.
- Is used to load store in store table. (not required just using it for ease of setup)
- Here are some of the pre-requisite (Note: It is tested on Mac OS X for now)
- Install latest virtual Box (5.2.12-122591 - VirtualBox-5.2.12-122591-OSX.dmg)
- Install Vagrant (2.1.2 - vagrant_2.1.2_x86_64.dmg)
- Install plugins (vbguest and hostmanager)
$ vagrant plugin install vagrant-hostmanager
$ vagrant plugin install vagrant-vbguest
- Checkout the code
$ git clone https://github.com/pawandeepthind/mulesoft-sandbox.git
- Change directory to mulesoft-sandbox/sandbox
$ cd mulesoft-sandbox/sandbox
- Execute vagrant up command (Note: This command may take some time for the first time, 10-15 mins)
$ vagrant up
- Import inventory project to anypoint studio using mulesoft-sandbox/inventory/pom.xml
Click File > Import > Maven based Mule project from pom.xml > Select project pom.xml file and import
- Right click on the imported inventory project and Validate in console that application is deployed successfully
Click on inventory project > Run As > Mule Application with Maven,
- Call API using following specification
POST /api/findinstore HTTP/1.1
Host: localhost:8081
Content-Type: application/json
Cache-Control: no-cache
{
"address": "49 W 27th St New York NY 10001",
"itemids": [
"10001",
"10002"
]
}Find the Postman collection link here for details on how to call API
- MySql DB:
| Property | Values |
|---|---|
| host | 10.0.20.20 |
| port | 3306 |
| user | root |
| password | password |
| dbname | inventory |
- SFTP:
| Property | Values |
|---|---|
| host | 10.0.20.20 |
| port | 22 |
| user | vagrant |
| password | vagrant |
| home dir | /home/vagrant |
Note: SQL statement used to find 5 nearby stores, this query is taken from the following discussion link
SELECT
id, (
3959 * acos (
cos ( radians(78.3232) )
* cos( radians( lat ) )
* cos( radians( lng ) - radians(65.3234) )
+ sin ( radians(78.3232) )
* sin( radians( lat ) )
)
) AS distance
FROM markers
ORDER BY distance
LIMIT 0 , 5;