Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Ecommerce Delivery Service

A Spring Boot REST API for an ecommerce delivery platform — manages users, user delivery addresses (with geospatial "nearby" search), products, and orders.

Tech Stack

Component Choice
Language / Build Java 21, Maven
Framework Spring Boot 3.4.3 (Web, Data JPA, Security, DevTools)
Database PostgreSQL + PostGIS (geospatial queries)
Schema management Liquibase
Query building QueryDSL (generates type-safe Q* classes)
Boilerplate Lombok

Project Structure

src/main/java/com/dwardel/
├── controller/   REST endpoints
├── service/      Business logic
├── repository/   Spring Data JPA repositories
├── model/        JPA entities
├── dto/          Data Transfer Objects returned to clients
src/main/resources/
├── application.properties     App + DB configuration
├── liquibase.properties       Used only for generating changelogs from an existing DB
└── db/                        Liquibase changelogs (create-tables, insert-rows, data-dictionary)

Request flow: Controller → Service → Repository (JPA) → PostgreSQL

Prerequisites

  • JDK 21
  • Maven 3.9+ (or use the included ./mvnw if present)
  • PostgreSQL 14+ with the PostGIS extension available

1. Set Up the Database

Create the database and enable PostGIS:

CREATE DATABASE ecommerce;
\c ecommerce
CREATE EXTENSION IF NOT EXISTS postgis;

Update credentials in src/main/resources/application.properties if they differ from your local setup:

spring.datasource.url=jdbc:postgresql://localhost:5432/ecommerce
spring.datasource.username=postgres
spring.datasource.password=root

Schema and seed data are managed by Liquibase and applied automatically on application startup (spring.liquibase.enabled=true, changelog: db/data-dictionary.xml) — no manual migration step is required.

2. Build

mvn clean install

This compiles the project and generates QueryDSL Q* classes (used for complex joins/criteria queries) into target/generated-sources.

3. Run

mvn spring-boot:run

Or run the packaged jar:

mvn clean package
java -jar target/delivery-0.0.1-SNAPSHOT.jar

On successful startup you'll see Spring Boot's banner followed by:

Started DeliveryApplication in x.xxx seconds

The app runs on http://localhost:8080 by default.

Authentication

Spring Security is enabled with a single default in-memory user (configured in application.properties):

Username: admin
Password: admin123

Every endpoint requires HTTP Basic Auth with these credentials, e.g. add -u admin:admin123 to curl calls or configure Basic Auth in Postman.

API Endpoints & Sample Output

Health check

curl -u admin:admin123 http://localhost:8080/
Welcome to my Spring Boot application!

Users — GET /users

curl -u admin:admin123 http://localhost:8080/users
[
  { "id": 1, "email": "john@example.com" }
]

User by ID — GET /users/{id}

curl -u admin:admin123 http://localhost:8080/users/1

User with address — GET /users/{id}/address

curl -u admin:admin123 http://localhost:8080/users/1/address

Create user — POST /users

curl -u admin:admin123 -X POST http://localhost:8080/users \
  -H "Content-Type: application/json" \
  -d '{"email":"jane@example.com","password":"secret"}'
{ "id": 2, "email": "jane@example.com" }

Products — GET /api/products

curl -u admin:admin123 http://localhost:8080/api/products
[
  { "id": 1, "name": "Wireless Mouse", "description": "Ergonomic mouse", "price": 19.99, "stockQuantity": 100 }
]

Save a user address — POST /api/user-address/save

curl -u admin:admin123 -X POST "http://localhost:8080/api/user-address/save?userId=1&address=221B%20Baker%20St&latitude=51.5237&longitude=-0.1585&placeId=abc123"

Find nearby addresses — GET /api/user-address/nearby

Returns all addresses within radius meters of the given coordinates (uses PostGIS distance calculation).

curl -u admin:admin123 "http://localhost:8080/api/user-address/nearby?latitude=51.5237&longitude=-0.1585&radius=5000"

All user addresses — GET /api/user-address

curl -u admin:admin123 http://localhost:8080/api/user-address

Running Tests

mvn test

Notes

  • spring.jpa.hibernate.ddl-auto=none — schema changes are managed exclusively through Liquibase, not Hibernate auto-DDL.
  • spring.jpa.show-sql=true and debug-level Hibernate logging are enabled by default for local development; disable them for production.
  • liquibase.properties (and the mvn liquibase:generateChangeLog ... command in it) is only used to generate a changelog by diffing against an existing database — it is not needed for normal startup.
  • HikariCP connection pool is tuned via spring.datasource.hikari.* properties in application.properties.

About

Spring Boot REST API for an ecommerce delivery platform, with PostGIS-powered geospatial "nearby address" search.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages