Spring Boot pricing microservice sample: REST CRUD + actuator + PostgreSQL
Find a file
anaeem b03d285665
Some checks failed
build-image / build (push) Has been cancelled
CI: build with docker (the runner provides docker, not podman)
2026-06-15 15:17:10 +01:00
.gitea/workflows CI: build with docker (the runner provides docker, not podman) 2026-06-15 15:17:10 +01:00
db Initial commit: Spring Boot pricing microservice 2026-06-11 08:31:05 +01:00
src/main Initial commit: Spring Boot pricing microservice 2026-06-11 08:31:05 +01:00
.gitignore Initial commit: Spring Boot pricing microservice 2026-06-11 08:31:05 +01:00
Containerfile Add Containerfile + Gitea build-and-push workflow 2026-06-15 15:14:11 +01:00
pom.xml Initial commit: Spring Boot pricing microservice 2026-06-11 08:31:05 +01:00
README.md Initial commit: Spring Boot pricing microservice 2026-06-11 08:31:05 +01:00

pricing-svc

Spring Boot pricing microservice — REST CRUD over PostgreSQL, actuator, and a tiny business-logic pricing engine. Packaged as an executable fat JAR.

Endpoints

Method Path Description
GET /api/pricelists List all price lists
POST /api/pricelists Create a price list
GET /api/pricelists/{id} Get a single price list
PUT /api/pricelists/{id} Update a price list
DELETE /api/pricelists/{id} Delete a price list
GET /api/pricelists/{id}/rules List rules for a price list
POST /api/pricelists/{id}/rules Add a rule to a price list
GET /api/price?sku=X[&basePrice=N] Compute effective price for SKU
GET /actuator/health Health check
GET /actuator/info App info
GET /actuator/metrics Metrics

How to run

Prerequisites

  • Java 17+
  • PostgreSQL 14+ running on localhost:5432

Database setup

# Create DB and user
psql -U postgres -c "CREATE USER pricing WITH PASSWORD 'pr1c1ng-s3cret';"
psql -U postgres -c "CREATE DATABASE pricing OWNER pricing;"

# Apply schema + seed
psql -U pricing -d pricing -f db/init.sql

Start the service

java -jar target/pricing-svc-1.0.0.jar

Overriding datasource at runtime (no config file change needed):

java -jar target/pricing-svc-1.0.0.jar \
  --spring.datasource.url=jdbc:postgresql://db-host:5432/pricing \
  --spring.datasource.password=my-other-secret

Build

mvn -B -DskipTests package

Example requests

# List price lists
curl http://localhost:8080/api/pricelists

# Get effective price for a laptop SKU (20% discount from Electronics Promo)
curl "http://localhost:8080/api/price?sku=ELEC-LAPT-001&basePrice=999.99"

# Get effective price — no matching rule, full price returned
curl "http://localhost:8080/api/price?sku=UNKNOWN-001&basePrice=50.00"

# Create a price list
curl -X POST http://localhost:8080/api/pricelists \
  -H 'Content-Type: application/json' \
  -d '{"name":"VIP","description":"VIP customer pricing","active":true}'

# Add a rule
curl -X POST http://localhost:8080/api/pricelists/1/rules \
  -H 'Content-Type: application/json' \
  -d '{"skuPattern":"ELEC-%","discountPct":5,"basePrice":null,"active":true}'

Configuration notes

Property Default Notes
spring.datasource.url jdbc:postgresql://localhost:5432/pricing Override with env or CLI
spring.datasource.username pricing
spring.datasource.password pr1c1ng-s3cret Intentionally in plaintext — discovery test case
logging.file.name /var/log/pricing-svc/app.log Directory must be writable
server.port 8080

Seed summary

3 price lists, 10 rules seeded by db/init.sql:

Price List Rules Notes
General Retail 3 5% all, 10% books, 8% apparel
Electronics Promo 4 15% all ELEC, 20% laptops, 12% audio, 25% TV-001 (expired 2025)
Clearance 3 30% all, 40% sports, 35% home goods