Microservice for managing product stock and calculating restock priorities.
- With Docker: Docker and Docker Compose
- Without Docker: Go 1.25+, PostgreSQL 16+
docker compose up --buildThe API will be available at http://localhost:8080 and Swagger UI at http://localhost:8080/swagger/index.html.
To stop:
docker compose downTo stop and remove the database volume:
docker compose down -vMake sure you have a PostgreSQL instance running locally.
cp .env.example .envEdit .env with your database credentials:
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=example
POSTGRES_DB=postgres
REPOSITORY_TYPE=POSTGRES
HANDLER_TYPE=HTTP
PAGINATION_DEFAULT_LIMIT=20
PAGINATION_MAX_LIMIT=100
PRIORITY_NEGATIVE_STOCK_FACTOR=1.5
PRIORITY_LEAD_TIME_FACTOR=1.2
PRIORITY_ZERO_SALES_FACTOR=0.5
SEED_FILE=internal/infrastructure/repository/db/seed.sqlgo run ./cmdThe API will be available at http://localhost:8080.
| Method | Route | Description |
|---|---|---|
| POST | /stock |
Create a product stock |
| GET | /stock |
List all product stocks |
| GET | /stock/:id |
Get a product stock by ID |
| PUT | /stock/:id |
Update a product stock |
| DELETE | /stock/:id |
Delete a product stock |
| GET | /stock/category/:category |
List product stocks by category |
| GET | /restock/priorities |
Get restock priorities |
| GET | /swagger/index.html |
Swagger UI |
curl -X POST http://localhost:8080/stock \
-H "Content-Type: application/json" \
-d '{
"name": "Oil Filter X",
"category": "engine",
"current_stock": 15,
"minimum_stock": 20,
"average_daily_sales": 4,
"lead_time_days": 5,
"unit_cost": 18.50,
"criticality_level": 3
}'curl "http://localhost:8080/stock?page=1&limit=10"curl http://localhost:8080/stock/{id}curl -X PUT http://localhost:8080/stock/{id} \
-H "Content-Type: application/json" \
-d '{
"current_stock": 25,
"minimum_stock": 30
}'curl -X DELETE http://localhost:8080/stock/{id}curl "http://localhost:8080/restock/priorities?page=1&limit=10"go test -v ./internal/domaingo test -v ./internal/application/testsRequires the application running (docker compose up -d or go run ./cmd):
go test ./tests/e2e/ -v -count=1With the application running, access the interactive API documentation at:
http://localhost:8080/swagger/index.html
go install github.com/swaggo/swag/cmd/swag@latest
swag init -g cmd/main.go -o docs --parseInternal