A RESTful API for product management built with Spring Boot and PostgreSQL. This project demonstrates modern Java development practices including REST API design, JPA/Hibernate data persistence, Docker containerization, and comprehensive testing.
- Features
- Technology Stack
- Architecture
- Getting Started
- API Documentation
- Testing
- Project Structure
- Contributing
- CRUD Operations: Complete Create, Read, Update, and Delete operations for products
- RESTful Design: Follows REST API best practices with proper HTTP status codes
- Data Validation: Robust input validation and error handling
- Database Integration: PostgreSQL with JPA/Hibernate ORM
- Docker Support: Fully containerized application with Docker Compose
- Health Monitoring: Spring Boot Actuator for application health checks
- Comprehensive Testing: Unit tests with Mockito for business logic
| Technology | Version | Purpose |
|---|---|---|
| Java | 17 | Programming Language |
| Spring Boot | 3.3.0 | Application Framework |
| Spring Data JPA | 3.3.0 | Data Access Layer |
| Spring Web | 3.3.0 | REST API |
| Spring Actuator | 3.3.0 | Application Monitoring |
| PostgreSQL | 13 | Relational Database |
| Maven | 3.8.4+ | Build Tool |
| Docker | Latest | Containerization |
| JUnit 5 | 5.x | Testing Framework |
| Mockito | 5.x | Mocking Framework |
The application follows a layered architecture pattern:
βββββββββββββββββββββββββββββββββββββββ
β Controller Layer (REST API) β
βββββββββββββββββββββββββββββββββββββββ€
β Service Layer (Business) β
βββββββββββββββββββββββββββββββββββββββ€
β Repository Layer (Data Access) β
βββββββββββββββββββββββββββββββββββββββ€
β PostgreSQL Database β
βββββββββββββββββββββββββββββββββββββββ
Key Components:
- ProductController: REST endpoints for product operations
- ProductService: Business logic and data transformation
- ProductRepository: Data access using Spring Data JPA
- Product: JPA entity representing the database table
- ProductDTO: Data Transfer Object for API responses
- Java 17 or higher
- Docker and Docker Compose
- Maven 3.8+ (optional, uses Maven Wrapper)
-
Clone the repository
git clone https://github.com/KayllaneGPina/case-java-I.git cd case-java-I -
Start the application
docker-compose up --build
-
Access the API
http://localhost:8080/api/products -
Health Check
http://localhost:8080/actuator/health
-
Start PostgreSQL
docker run -d \ --name postgres-db \ -e POSTGRES_DB=product_db \ -e POSTGRES_USER=postgres \ -e POSTGRES_PASSWORD=root123 \ -p 5432:5432 \ postgres:13
-
Run the application
./mvnw spring-boot:run
Database configuration can be modified in src/main/resources/application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/product_db
spring.datasource.username=postgres
spring.datasource.password=root123
spring.jpa.hibernate.ddl-auto=updatehttp://localhost:8080/api/products
GET /api/productsResponse: 200 OK
[
{
"id": 1,
"name": "Laptop",
"price": 999.99,
"description": "High-performance laptop"
}
]GET /api/products/{id}Response: 200 OK or 404 Not Found
{
"id": 1,
"name": "Laptop",
"price": 999.99,
"description": "High-performance laptop"
}POST /api/products
Content-Type: application/jsonRequest Body:
{
"name": "Laptop",
"price": 999.99,
"description": "High-performance laptop"
}Response: 201 Created
{
"id": 1,
"name": "Laptop",
"price": 999.99,
"description": "High-performance laptop"
}PUT /api/products/{id}
Content-Type: application/jsonRequest Body:
{
"name": "Updated Laptop",
"price": 1099.99,
"description": "Updated description"
}Response: 200 OK or 404 Not Found
{
"id": 1,
"name": "Updated Laptop",
"price": 1099.99,
"description": "Updated description"
}DELETE /api/products/{id}Response: 204 No Content or 404 Not Found
| Code | Description |
|---|---|
| 200 | OK - Request succeeded |
| 201 | Created - Resource created successfully |
| 204 | No Content - Resource deleted successfully |
| 404 | Not Found - Resource doesn't exist |
./mvnw test./mvnw test -Dtest=ProductControllerTestThe project includes comprehensive unit tests:
- ProductControllerTest: 8 test scenarios covering all REST endpoints
- Success and error cases for all CRUD operations
- Proper HTTP status code validation
- Mocked service layer for isolated testing
./mvnw clean packagecase-java-I/
βββ src/
β βββ main/
β β βββ java/br/com/prospertech/case_java/
β β β βββ Controller/
β β β β βββ ProductController.java
β β β βββ Service/
β β β β βββ ProductService.java
β β β βββ Repository/
β β β β βββ ProductRepository.java
β β β βββ Model/
β β β β βββ Product.java
β β β βββ DTO/
β β β β βββ ProductDTO.java
β β β βββ CaseJavaApplication.java
β β βββ resources/
β β βββ application.properties
β βββ test/
β βββ java/br/com/prospertech/case_java/
β βββ Controller/
β βββ ProductControllerTest.java
βββ Dockerfile
βββ docker-compose.yaml
βββ pom.xml
βββ README.md
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Java naming conventions
- Write unit tests for new features
- Maintain code coverage above 80%
- Use constructor injection over field injection
- Follow REST API best practices
This project is part of a technical assessment for Prospertech.
Kayllane Gomes Pina
- GitHub: @KayllaneGPina
Built with β€οΈ using Spring Boot