This is a backend application that provides a REST API to save, and search GEO locations. The API is built using Spring Boot, Maven, and uses Java 17. To save the locations, Postgres with the PostGIS extension is used.
- Docker
- Docker Compose
- Clone the repository:
git clone https://github.com/ehsansasanian/location-api.git
- Change directory to the project:
cd location-api
- Build the backend application using docker-compose build:
docker-compose build
- Start the services using:
docker-compose up
- The application uses a database, which is also automated using the docker-compose. It is configured to use an environment variable
SPRING_DATASOURCE_URLto connect to the database. You can check the file for more details. - Alternatively, it is possible to run the application and the database separately. Make sure a postgres with the PostGIS extension runs on
localhost:5433, with a properusername,password, anddatabase. Then the below command could be used to run the app: - Ensure sure
8080,5433, and5050ports are available on your device. The backend, postgres, and pgAdmin respectively use the ports to run on the machine.
mvn spring-boot:run
The application uses postgres-testcontainer to integrate the database. To test the application please use mvn test. Note that for accelerating the build process, tests are skipped within the build process.
Once the services are running, you can access the API endpoints using your preferred HTTP client.
Endpoint: POST /locations
Example Payload:
curl --location --request POST 'localhost:8080/location' --header 'Content-Type: application/json' --data-raw '{ "name": "John Doe", "latitude": -6.840598, "longitude": -54.070016, "type": "premium"}'
Example Response:
{
"id":1,
"name":"John Doe",
"latitude":-6.840598,
"longitude":-54.070016,
"type":"premium"
}
- acceptable values for type are
premium, andstandard
Example Payload For Search By Type
curl --location --request GET 'localhost:8080/location/premium'
Example Payload For Search In an Area
curl --location --request GET 'localhost:8080/location/area?p1Lat=-6.816893&p1Long=-54.091581&p2Lat=-54.028190&p2Long=-6.862297&limit=3'
Example Payload For Search By an Area and Type
curl --location --request GET 'localhost:8080/location/premium/area?p1Lat=-6.816893&p1Long=-54.091581&p2Lat=-54.028190&p2Long=-6.862297&limit=1'
- Note that
limitis an optional param in both above examples. If not provided, the app returns all found data.
Example Response
[
{
"name":"John Doe",
"latitude":-6.840598,
"longitude":-54.070016,
"type":"premium"
}
]
To check the changes in the database, you can use psql -h localhost -p 5433 -U postgres -d postgres and postgres as password. Alternatively, as the pgAdmin is included in the docker-compose file, it should be up and running on your machine. Simply click here in see the pgAdmin client in your browser.
To login, usetest@test.com as Username and test as Password.
To stop the services, please use Ctrl+c and to remove the containers use:
docker-compose down