A Spring Boot service that stores vehicle coordinates in Redis GEO and provides REST APIs to:
- Add vehicle locations
- Query nearest vehicles by a point or by a center vehicle
- Calculate distance between two vehicles
All responses are wrapped in a consistent CustomResponse<T> envelope, and paging is returned as CustomPage<T>.
- Client sends a JSON request (
VehicleLocationRequest) containing:vehicleName,latitude,longitude
- Service writes the coordinate using Redis GEO (
GEOADD) and reads back optional metadata (e.g., geohash). - Returns:
200 OKwithCustomResponse<VehicleLocationResponse>
- Client sends a JSON request (
FindNearestByPointRequest) containing:longitude,latitude,km- optional paging/sorting inherited from
CustomPagingRequest
- Service searches Redis GEO using a circle radius query (includes coordinates & distance).
- Returns:
200 OKwithCustomResponse<CustomPage<VehicleLocationResponse>>
- Client sends a JSON request (
FindNearestByMemberRequest) containing:centerVehicleName,km- optional paging/sorting inherited from
CustomPagingRequest
- Service searches Redis GEO around the center vehicle (member-based radius).
- Returns:
200 OKwithCustomResponse<CustomPage<VehicleLocationResponse>>
- Client sends a JSON request (
VehicleDistanceRequest) containing:vehicleA,vehicleB(must be different)
- Service calculates the distance using Redis GEO distance query.
- Returns:
200 OKwithCustomResponse<VehicleDistanceResponse>
400 Bad Request— Validation errors (@Valid) such as missing fields, invalid ranges (e.g.,km < 1), etc.404 Not Found— Vehicle not found (e.g., querying distance or member-center not in Redis).409 Conflict— Vehicle already exists (if your service enforces uniqueness on add).500 Internal Server Error— Redis/data access failures or unexpected errors.
Custom Exceptions (examples)
VehicleAlreadyExistsException→409 CONFLICTVehicleNotFoundException→404 NOT_FOUNDGeoSearchFailedException→500 INTERNAL_SERVER_ERROR
| Method | URL | Description | Request Body | Headers | Response | Status Codes |
|---|---|---|---|---|---|---|
| POST | /api/vehicles/location |
Add a vehicle location into Redis GEO. | JSON: VehicleLocationRequest |
Content-Type: application/json |
CustomResponse<VehicleLocationResponse> |
200, 400, 409, 500 |
| POST | /api/vehicles/nearest/point |
Find nearest vehicles around a longitude/latitude within km radius (paged). |
JSON: FindNearestByPointRequest |
Content-Type: application/json |
CustomResponse<CustomPage<VehicleLocationResponse>> |
200, 400, 500 |
| POST | /api/vehicles/nearest/member |
Find nearest vehicles around a center vehicle within km radius (paged). |
JSON: FindNearestByMemberRequest |
Content-Type: application/json |
CustomResponse<CustomPage<VehicleLocationResponse>> |
200, 400, 404, 500 |
| POST | /api/vehicles/distance |
Calculate distance between two vehicles (km). | JSON: VehicleDistanceRequest |
Content-Type: application/json |
CustomResponse<VehicleDistanceResponse> |
200, 400, 404, 500 |
- Java 25
- Spring Boot 3.0
- Restful API
- Open Api (Swagger)
- Maven
- Junit5
- Mockito
- Integration Tests
- Mapstruct
- Docker
- Docker Compose
- CI/CD (Github Actions)
- Postman
- Redis
- Kubernetes
- JaCoCo (Test Report)
- AOP
Import postman collection under postman_collection folder
REDIS_HOST=localhost
REDIS_PORT=6379
http://localhost:1441/swagger-ui/index.html
After the command named mvn clean install completes, the JaCoCo report will be available at:
target/site/jacoco/index.html
Navigate to the target/site/jacoco/ directory.
Open the index.html file in your browser to view the detailed coverage report.
To build and run the application with Maven, please follow the directions shown below;
$ git clone https://github.com/Rapter1990/geospatial-location-with-redis.git
$ cd geospatial-location-with-redis
$ docker-compose -f docker-compose-local.yml up -d
$ mvn clean install
$ mvn spring-boot:runThe application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
$ cd geospatial-location-with-redis
$ docker-compose -f docker-compose.yml up -d If you change anything in the project and run it on Docker, you can also use this command shown below
$ cd geospatial-location-with-redis
$ docker-compose -f docker-compose.yml up -d --build$ docker exec -it redis redis-cli
$ KEYS *
$ ZRANGE vehicle_location 0 -1
$ KEYS *To run the application, please follow the directions shown below;
- Start Minikube
$ minikube start- Open Minikube Dashboard
$ minikube dashboard- To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder
$ kubectl apply -f k8s- To learn url to be used for App through Minikube
minikube service geospatial-location-with-redis --urlIt will print something like:
http://127.0.0.1:xxxxxThen call:
http://127.0.0.1:xxxxx/api/vehicles/nearest/pointhttps://hub.docker.com/repository/docker/noyandocker/geospatial-location-with-redis/general
