Level 2: MySQL with Relationships - Completed ✅
📋 Overview
Complete REST API for fruit and provider management with MySQL database and bidirectional JPA relationships.
✨ Features
- ✅ Full CRUD operations for Provider and Fruit entities
- ✅ MySQL database with JPA/Hibernate
- ✅ Bidirectional relationship @onetomany / @manytoone
- ✅ DTO pattern with nested provider data in fruit responses
- ✅ Custom exceptions: DuplicateResourceException, BusinessException
- ✅ Global exception handling (404, 409, 400, 500)
- ✅ Unit tests with Mockito (19 tests)
- ✅ Integration tests with MockMvc (20 tests)
- ✅ Docker multi-stage build and docker-compose for MySQL
- ✅ OpenAPI/Swagger documentation
- ✅ phpMyAdmin available at http://localhost:8080
🔗 API Endpoints
Providers
| Method |
Endpoint |
Description |
| POST |
/providers |
Create a new provider |
| GET |
/providers |
List all providers |
| GET |
/providers/{id} |
Get provider by ID |
| GET |
/providers/{id}/details |
Get provider with its fruits |
| PUT |
/providers/{id} |
Update provider |
| DELETE |
/providers/{id} |
Delete provider (fails if has fruits) |
Fruits
| Method |
Endpoint |
Description |
| POST |
/fruits |
Create a new fruit (requires providerId) |
| GET |
/fruits |
List all fruits with provider data |
| GET |
/fruits/{id} |
Get fruit by ID with provider data |
| GET |
/fruits/by-provider?providerId={id} |
List fruits by provider |
| PUT |
/fruits/{id} |
Update fruit |
| DELETE |
/fruits/{id} |
Delete fruit |
🚀 How to Run
Prerequisites
Start MySQL with Docker Compose
cd level2-fruit-api-mysql
docker-compose up -d