Skip to content

Level 1 - H2 CRUD API Completed

Choose a tag to compare

@ecantosf ecantosf released this 30 Mar 05:02
· 36 commits to main since this release

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