Skip to content

Latest commit

 

History

52 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍏 Fruit Order API with MongoDB

📄 Description

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).


💻 Technologies Used

  • 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

📋 Requirements

  • 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

🛠️ Installation

  1. Clone the repository

    git clone https://github.com/alaw810/4.2-Spring-CRUD-MongoDB.git
    cd 4.2-Spring-CRUD-MongoDB
  2. Build the project

    ./mvnw clean package -DskipTests
  3. Run the containers

    docker compose up --build

▶️ Execution

Once the containers are running:


🌐 API Endpoints

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

🧪 Testing

The project follows a TDD workflow using JUnit 5 and MockMvc.

You can run all tests with:

./mvnw test

Test coverage includes:

  • Service layer unit tests
  • Controller integration tests
  • Validation unit tests (ValidDeliveryDateValidator)
  • Global exception handling tests
  • MongoDB integration via embedded tests

🐳 Docker Setup

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=admin

🧠 Author

Adrià Lorente
📍 IT Academy – Java Back-End Development
📚 Exercise: S04.T02.N03 – API REST with Spring Boot (Level 3 - MongoDB)

About

REST API for managing fruit orders with Spring Boot, MongoDB, and Docker, developed using TDD.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages