This is server side restful API developed using Spring boot. It allows a retail manager to
- Add a shop
- The retail manager can post a JSON payload to a shop endppint containing shopName, shopAddress.number, shopAddress.postCode.
- This API uses Google Maps Geocoding API tp retreive the longitude and latitude and store all information to a server side in-memory data store.
- Find the nearest shop by giving cutomerLongitude and customerLatitude
- Gradle 3.3
- Java 8
- Spring-boot
- Google Map Geocoding API
- Jacoco
It is a gradle based java application, use the following to package it in a jar.
gradle build
To build without running tests
gradle build -x test
On successful build the jar can be found at build/libs/
path.
In our case, it is at local-path/retail-manager/build/libs/retail-manager-1.0.jar
Once the application is built, you have the jar, it can be run with the following command -
java -jar <path>\retail-manager\build\libs\retail-manager-1.0.jar
Or, simply run the main() of ApplicationLauncher.java
Or, the below command also run the application -
gradle run
You will see the following message after a successful start up -
. ____ _ __ _ _
/\ / ' __ _ () __ __ _ \ \ \
( ( )__ | '_ | '| | ' / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
' || .__|| ||| |_, | / / / /
=========||==============|/=////
:: Spring Boot :: (v1.4.0.RELEASE)
Retail Manager is running!
The application has test cases as well. To run, use the below -
gradle test
Test Summary can be found at src/retail-manager/build/reports/tests/test/index.html
It also has "jacoco" plugin to see the code coverage -
gradle test jacocoTestReport
The coverage can be veiwed at - src/retail-manager/build/reports/coverage/index.html
There are two APIs-
- This api adds a shop to the in-memory database.
URI - /shop/add
REQUEST BODY - {"shopName" : "Hasan Shop- Kharadi","shopAddress" : {"number": "EON IT Park, Kharadi, Pune","postCode" : 411014}}
HTTP METHOD - POST
HTTP RESPONSE - 201 OK
RESPONSE BODY - {"success": true}
e.g - http://localhost:8080/shop/add
- This api finds the nearest shop to the location (latitude, longtitude) passed in the request parameter.
URI - /shop/find
REQUEST PARAMS - customerLatitude, customerLongitude
HTTP METHOD - GET
HTTP RESPONSE - 200 OK
RESPONSE BODY - {"shopName":"Hasan Shop- Kharadi","shopAddress":{"number":"EON IT Park, Kharadi, Pune","postCode":411014},"shopLatitude":18.5515629,"shopLongitude":73.95096780000002}
e.g - http://localhost:8080/shop/find?customerLatitude=18.5793&customerLongitude=73.9823