This repository contains a Product Management application developed using Java 17 and Spring Boot 3. The application provides functionalities to manage products, including creating, retrieving, updating, and deleting products.
- Features
- Technologies Used
- Installation
- Running the Application
- Testing the API with Postman
- Unit Tests
- Retrieve a list of all products with pagination support.
- Retrieve a specific product by its ID.
- Create a new product with detailed attributes.
- Update an existing product by its ID.
- Delete a product by its ID.
- Handle cases where a product is not found with appropriate error responses.
- Java 17
- Spring Boot 3
- PostgreSQL
- Maven
- JUnit (for unit testing)
-
Clone the repository:
git clone https://github.com/yourusername/product-management-api.git
-
Navigate to the project directory:
cd product-management-api
-
Install dependencies:
mvn install
-
Set up your PostgreSQL database and configure the connection in
src/main/resources/application.properties
:spring.datasource.url=jdbc:postgresql://localhost:5432/yourdbname spring.datasource.username=yourusername spring.datasource.password=yourpassword
To run the application, use the following command:
mvn spring-boot:run
The application should start on http://localhost:8081
.
You can use Postman to test the API endpoints. Follow these steps:
-
Import the Postman Collection:
- Download the Postman collection JSON file from the
postman_collections
folder in this repository. - Open Postman and select "Import" to add the collection.
- Download the Postman collection JSON file from the
-
API Endpoints:
- GET /products: Retrieve all products (pagination supported).
- GET /products/{id}: Retrieve a product by ID. Returns a 404 if the product is not found.
- POST /products: Create a new product. Send a JSON body with product details.
- PUT /products/{id}: Update an existing product by ID. Only the fields provided will be updated.
- DELETE /products/{id}: Delete a product by ID.
-
Testing:
- Run the requests in Postman to test each endpoint. Ensure you check for the correct status codes and responses.
Unit tests have been created for the ProductService
to ensure functionality. You can run the tests using:
mvn test