- The application is configured to run on port 8088
- The application use an in memory DB - H2 Database
- The application was developed using Spring Boot. This is a stand alone application where everything you need is embedded on it (Tomcat, DB, ...)
- The application will populate the DB with 10000 records previously generated
- I'm using the Google Maps API to get information from given coordinates
- In case you prefer to clone the repository, build and run by yourself, instead of execute the .jar file, you will need a Google Maps API key
- To get a Google Maps API key
- To set a key in the app
java -jar inauth-0.0.1-SNAPSHOT.jar
- I've sent the .jar file to your email
Clone the GitHub project https://github.com/hyalen-moreira/inauth.git
https://github.com/hyalen-moreira/inauth/blob/master/src/main/resources/data-h2.sql
Once the application is running, open a browser of your choice and:
- To get all coordinates - GET
- To get data from a specific coordinate - GET
- http://localhost:8088/inauth/api/locations/40.714224,-73.961452
- If the coordinate doens't exist in the DB, the app will return
404 - No Found
- Otherwise the application will access a Google Maps API and will return information about the coordinate
- To add a new coordinate - POST
- http://localhost:8088/inauth/api/locations
- Inform the latitude and longitude on body of the http post request
{"latitude" : "42.714224", "longitude" : "-53.961452"}
- http://localhost:8088/inauth/api/assessment/40.714224,-73.961452 - GET
- If the coordinates is within USA you will see the message:
The given coordinate is withing the USA
- Otherwise you will see a report about distances of pre-defined cities.
- If the coordinates is within USA you will see the message:
- Accessing the http://localhost:8088/inauth/api/assessment/19.42847,-99.12766 endpoint you will see:
The given coordinate has: 7020.238077159492 MILES of distance from TOKYO 2643.954095668077 MILES of distance from LIMA 8616.364079471108 MILES of distance from RIYADH 4633.421762585401 MILES of distance from REYKJAVIK 8061.066959776479 MILES of distance from SYDNEY 6016.952416298471 MILES of distance from ZURICH 0.0 MILES of distance from MEXICO and it is also within 500 MILES of distance of this city.
- To access the in memory database
- http://localhost:8088/h2-console and then inform:
- Driver Class:
org.h2.Driver
- JDBC URL:
jdbc:h2:mem:inauth
- Login:
inauth
- Password:
inauth
- Driver Class:
- Press the
connect
button
- http://localhost:8088/h2-console and then inform:
Create a DB containing 10.000 random entries for valid latitude and longitude coordinates and performing some operations using the DB.
The following areas were addressed: Java, Configuration, Architecture, Logic, Exception Handling, Logs, Spring, Persistence, REST, Tests, Documentation and Geocoding.
I've been using the H2 in memory DB. From H2 Database console, I run the following command to export the DB to be used as seed data:
CALL CSVWRITE(
'/Users/hyalencaldeira/Documents/workspace/inauth/src/main/resources/data-h2.sql',
'SELECT CONCAT(
CHAR(40),
LATITUDE,
CHAR(44),
LONGITUDE,
CHAR(41))
FROM
LOCATION',
'charset=UTF-8 fieldSeparator=' || CHAR(9)
);
I've used spring-boot to make the server up, runnable and ready to receive HTTP requests. The server is started on port 8088.
Besides the Micro Service to fetch coordinates information, I've also added solution performing operations through coordinates of some locations:
getAllDataSets
- GET method to return all data in the DB.getData(latitude, longitude)
- GET method to return if the coordinates exists in the DB.addData(latitude, longitude)
- POST method to add coordinate to the DB.- Apart of the above web services, I've also added the
getAssessment(latitude, longitude)
service - GET method to return a distance's report.
- Given the entry's coordinates, determine if those coordinates are within the United States.
- If they're not within the United States, determine if the coordinates are within 500 miles of the following cities
- Tokyo, Japan
- Sydney, Australia
- Riyadh, Saudi Arabia
- Zurich, Switzerland
- Reykjavik, Iceland
- Mexico City, Mexico
- Lima, Peru
- For each of the above, tell how far away the entry's coordinates are from each city
- You may see an example of this requirement accessing the http://localhost:8088/inauth/api/assessment/19.42847,-99.12766 endpoint
- Missing - I've added unit tests for all the existing classes in the workspace.
- Missing - I've added Spring Integration Tests for all the
API endpoints
.
-
List Locations: [GET]
http://localhost:8088/api/locations
-
Fetch Location Details: [GET]
http://localhost:8088/api/locations/{latitude,longitude}
-
Add Location: [POST]
http://localhost:8088/api/locations
-
Fetch Report Details: [GET]
http://localhost:8088/api/assessment/{latitude,longitude}
- To test, you should have Java 8, Maven and Git installed.
- The sample data has been pre-loaded so that the
endpoints
can be tested. Please refer todata-h2.sql
on https://github.com/hyalen-moreira/inauth/blob/master/src/main/resources/data-h2.sql.
- Google Maps API
- Java 8.x
- Maven 3.x
- Spring Framework 4.x
- Spring Boot 1.5.6
- Google Maps API
- Hibernate
- JPA
- H2 database
- JUnit 4.x
- Spring Integration Tests
- Project Lombok