Skip to content

KayllaneGPina/case-java-I

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Case Java I - Product Management API

Java Spring Boot PostgreSQL Docker

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.

πŸ“‹ Table of Contents

✨ Features

  • 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 Stack

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

πŸ— Architecture

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

πŸš€ Getting Started

Prerequisites

  • Java 17 or higher
  • Docker and Docker Compose
  • Maven 3.8+ (optional, uses Maven Wrapper)

Installation & Running

Option 1: Using Docker Compose (Recommended)

  1. Clone the repository

    git clone https://github.com/KayllaneGPina/case-java-I.git
    cd case-java-I
  2. Start the application

    docker-compose up --build
  3. Access the API

    http://localhost:8080/api/products
    
  4. Health Check

    http://localhost:8080/actuator/health
    

Option 2: Local Development

  1. 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
  2. Run the application

    ./mvnw spring-boot:run

Configuration

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

πŸ“š API Documentation

Base URL

http://localhost:8080/api/products

Endpoints

1. Get All Products

GET /api/products

Response: 200 OK

[
  {
    "id": 1,
    "name": "Laptop",
    "price": 999.99,
    "description": "High-performance laptop"
  }
]

2. Get Product by ID

GET /api/products/{id}

Response: 200 OK or 404 Not Found

{
  "id": 1,
  "name": "Laptop",
  "price": 999.99,
  "description": "High-performance laptop"
}

3. Create Product

POST /api/products
Content-Type: application/json

Request Body:

{
  "name": "Laptop",
  "price": 999.99,
  "description": "High-performance laptop"
}

Response: 201 Created

{
  "id": 1,
  "name": "Laptop",
  "price": 999.99,
  "description": "High-performance laptop"
}

4. Update Product

PUT /api/products/{id}
Content-Type: application/json

Request 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"
}

5. Delete Product

DELETE /api/products/{id}

Response: 204 No Content or 404 Not Found

HTTP Status Codes

Code Description
200 OK - Request succeeded
201 Created - Resource created successfully
204 No Content - Resource deleted successfully
404 Not Found - Resource doesn't exist

πŸ§ͺ Testing

Run All Tests

./mvnw test

Run Specific Test Class

./mvnw test -Dtest=ProductControllerTest

Test Coverage

The 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

Build the Project

./mvnw clean package

πŸ“ Project Structure

case-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

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Code Standards

  • 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

πŸ“ License

This project is part of a technical assessment for Prospertech.

πŸ‘₯ Author

Kayllane Gomes Pina


Built with ❀️ using Spring Boot

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •