The goal of this project is to develop a REST API that allows managing fruit orders.
Each order contains a client name, a delivery date, and one or more fruit items with quantities.
The system supports creating, retrieving, updating, and deleting orders, following REST principles and using TDD (Test-Driven Development).
- Java 21
- Spring Boot 3.4+
- Spring Web
- Spring Data MongoDB
- Spring Validation
- MongoDB 7.0
- Mongo Express (visual admin tool)
- Docker & Docker Compose
- JUnit 5 & MockMvc
- Maven
- Git & Conventional Commits
- Java 21+
- Maven 3.9+
- Docker & Docker Compose installed
- Port 8080 available for the API
- Port 8081 available for Mongo Express
- Port 27017 available for MongoDB
-
Clone the repository
git clone https://github.com/alaw810/4.2-Spring-CRUD-MongoDB.git cd 4.2-Spring-CRUD-MongoDB -
Build the project
./mvnw clean package -DskipTests
-
Run the containers
docker compose up --build
Once the containers are running:
- API: http://localhost:8080/orders
- Mongo Express UI: http://localhost:8081
| Method | Endpoint | Description | Status Codes |
|---|---|---|---|
POST |
/orders |
Create a new order | 201, 400 |
GET |
/orders |
Retrieve all orders | 200 |
GET |
/orders/{id} |
Retrieve an order by its ID | 200, 404 |
PUT |
/orders/{id} |
Update an existing order | 200, 404, 400 |
DELETE |
/orders/{id} |
Delete an order by ID | 204, 404 |
The project follows a TDD workflow using JUnit 5 and MockMvc.
You can run all tests with:
./mvnw test- Service layer unit tests
- Controller integration tests
- Validation unit tests (
ValidDeliveryDateValidator) - Global exception handling tests
- MongoDB integration via embedded tests
The project includes a complete Docker Compose setup with three services:
services:
mongodb:
image: mongo:7.0
environment:
MONGO_INITDB_DATABASE: fruit_order_db
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: root
mongo-express:
image: mongo-express:1.0.2
environment:
ME_CONFIG_MONGODB_SERVER: mongodb
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: root
fruit-order-api:
build: .
environment:
MONGO_URI: mongodb://root:root@mongodb:27017/fruit_order_db?authSource=adminAdrià Lorente
📍 IT Academy – Java Back-End Development
📚 Exercise: S04.T02.N03 – API REST with Spring Boot (Level 3 - MongoDB)