ShopAPI is a Spring Boot 2.6 (Java 17) REST service that manages a simple catalog of computer hardware: hard drives, laptops, monitors, and personal computers. It exposes CRUD-style endpoints for each product type and includes lightweight analytics endpoints for inventory counts and in-memory endpoint usage stats. The service uses PostgreSQL via Spring Data JPA.
This project and its infrastructure were created with the help of GPT-5.2-Codex as part of AI Subject Laboratory Work.
- Docker with Docker Compose v2
docker compose -f docker-compose.local.yml up --build
The API will be available at:
docker compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from tests
The container setup uses these defaults:
SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shopSPRING_DATASOURCE_USERNAME=postgresSPRING_DATASOURCE_PASSWORD=shopAPISPRING_JPA_HIBERNATE_DDL_AUTO=update
- Controllers: REST endpoints in
src/main/java/testtask/shift/shopapi/controller. - Services: Business logic in
src/main/java/testtask/shift/shopapi/service. - Repositories: Spring Data JPA repositories in
src/main/java/testtask/shift/shopapi/repository. - Models: JPA entities in
src/main/java/testtask/shift/shopapi/model. - Config: Web configuration in
src/main/java/testtask/shift/shopapi/config.
HTTP request -> Controller -> Service -> Repository -> PostgreSQL
Analytics endpoints are computed at runtime:
- Inventory counts are pulled from repository
count()methods. - Endpoint usage stats are stored in-memory by a request interceptor.
Base URLs:
/api/hdds/api/laptops/api/monitors/api/pcs
Common operations:
GET /api/<type>- list itemsGET /api/<type>/{id}- get item by idPOST /api/<type>/add- create itemPUT /api/<type>/{id}- update item (id is forced to the path id)
GET /api/analytics/counts- Returns total and per-category counts.
GET /api/analytics/usage- Returns endpoint usage counts since the app started.
API documentation is available at:
http://localhost:8080/swagger-ui/index.html
All product types share common fields:
id(generated)seriesNumberproducerpricenumberOfProductsInStock
Type-specific fields:
- HardDrive:
capacity - Laptop:
size(enum) - Monitor:
diagonal - PersonalComputer:
formFactor(enum)
- The project targets Java 17.
- Default database is PostgreSQL; schema is auto-created/updated on start.
- Analytics usage stats are in-memory and reset on restart.
GitHub Actions workflow builds and tests via Docker Compose, then pushes an image to GHCR and can deploy to a VPS via Docker Compose when secrets are configured.