Skip to content

Releases: ecantosf/S4.02-REST-API-with-Spring-Boot

Complete Project - All Three Levels Completed

Choose a tag to compare

@ecantosf ecantosf released this 02 Apr 15:56

Project Overview

Three independent Spring Boot REST APIs implementing full CRUD operations with different databases.

Level Database Status Tests
Level 1 H2 ✅ Complete 13 tests
Level 2 MySQL ✅ Complete 39 tests
Level 3 MongoDB ✅ Complete 21 tests

Level 1 - H2 CRUD API

Features

✅ Full CRUD operations for Fruit entity
✅ H2 in-memory database with JPA/Hibernate
✅ DTO pattern with Bean Validation
✅ Global exception handling (404, 400, 500)
✅ Unit tests with Mockito (6 tests)
✅ Integration tests with MockMvc (7 tests)
✅ Docker multi-stage build
✅ OpenAPI/Swagger documentation
✅ H2 Console available at /h2-console

Level 2 - MySQL with 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/

Level 3 - MongoDB with Embedded Documents

Features
✅ Full CRUD operations for Order entity
✅ MongoDB database with Spring Data MongoDB
✅ Embedded documents (OrderItem inside Order)
✅ DTO pattern with nested item data
✅ Custom validation: @FutureDeliveryDate (delivery date must be at least tomorrow)
✅ Global exception handling (404, 400, 500)
✅ Unit tests with Mockito (10 tests)
✅ Integration tests with MockMvc (11 tests)
✅ Docker multi-stage build and docker-compose for MongoDB
✅ OpeAPI/Swagger documentation
✅ Mongo Express available at http://localhost:8081/

Level 2 - MySQL with Relationships Completed

Choose a tag to compare

@ecantosf ecantosf released this 31 Mar 11:51

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

  • Docker Desktop running

Start MySQL with Docker Compose

cd level2-fruit-api-mysql
docker-compose up -d

Level 1 - H2 CRUD API Completed

Choose a tag to compare

@ecantosf ecantosf released this 30 Mar 05:02

Level 1: H2 CRUD API - Completed ✅

Overview

Complete REST API for fruit inventory management using H2 in-memory database.

Features

  • ✅ Full CRUD operations (Create, Read, Update, Delete)
  • ✅ H2 in-memory database with JPA/Hibernate
  • ✅ DTO pattern with Bean Validation
  • ✅ Global exception handling (404, 400, 500)
  • ✅ Unit tests with Mockito (6 tests)
  • ✅ Integration tests with MockMvc (7 tests)
  • ✅ Docker multi-stage build
  • ✅ OpenAPI/Swagger documentation

API Endpoints

Method Endpoint Description
POST /fruits Create a new fruit
GET /fruits List all fruits
GET /fruits/{id} Get fruit by ID
PUT /fruits/{id} Update fruit
DELETE /fruits/{id} Delete fruit

How to Run

With Maven

cd level1-fruit-api-h2
mvn spring-boot:run

#### With Docker
cd level1-fruit-api-h2
docker build -t fruit-api-h2:1.0.0 .
docker run -d -p 8081:8081 --name fruit-h2-app fruit-api-h2:1.0.0

#### Testing
cd level1-fruit-api-h2
mvn test

### Documentation
- Swagger UI: http://localhost:8081/swagger-ui.html
- H2 Console: http://localhost:8081/h2-console

### Project Structure
level1-fruit-api-h2/
├── src/main/java/.../fruit/
│   ├── controller/FruitController.java
│   ├── model/Fruit.java
│   ├── repository/FruitRepository.java
│   ├── service/FruitService.java
│   ├── dto/request/FruitRequestDTO.java
│   ├── dto/response/FruitResponseDTO.java
│   └── exception/GlobalExceptionHandler.java
├── src/test/java/.../fruit/
│   ├── service/FruitServiceTest.java
│   └── controller/FruitControllerTest.java
├── Dockerfile
└── pom.xml

### Status
- Level 1: ✅ Complete
- Level 2: ⏳ Pending
- Level 3: ⏳ Pending