Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# REST API (Spring Boot)

This document describes the RESTful API endpoints exposed by the Spring Boot backend for managing products and categories. The application runs on port `9090`.

## Product Controller (`/products`)

This controller provides endpoints for managing product information.

### 1. Create a New Product (`POST /products`)

* **Description:** Creates a new product in the inventory.
* **Request Body:**
```json
{
"name": "Product Name",
"categoryName": "Category Name",
"unitPrice": 10.0,
"expirationDate": "2025-12-31",
"inStock": 100
}
```
* `name` (string, required): The name of the product.
* `categoryName` (string, required): The name of the category to which the product belongs.
* `unitPrice` (number, required): The price of a single unit of the product.
* `expirationDate` (string, optional): The expiration date of the product (YYYY-MM-DD).
* `inStock` (integer, required): The current number of units in stock.
* **Response:**
* **Status Code:** `201 Created`
* **Response Body:** The newly created `Product` object.
```json
{
"id": "uniqueProductId",
"name": "Product Name",
"category": {
"id": "categoryId",
"categoryName": "Category Name"
},
"unitPrice": 10.0,
"expirationDate": "2025-12-31",
"inStock": 100,
"createdAt": "2025-05-29",
"updatedAt": null
}
```

### 2. Update an Existing Product (`PUT /products/{id}`)

* **Description:** Updates the information of an existing product.
* **Path Variable:**
* `id` (string, required): The unique ID of the product to update.
* **Request Body:** Same as the request body for creating a product.
* **Response:**
* **Status Code:** `200 OK`
* **Response Body:** The updated `Product` object.
* **Status Code:** `404 Not Found` If the product with the given ID does not exist.

### 3. Delete a Product (`DELETE /products/{id}`)

* **Description:** Deletes a product from the inventory.
* **Path Variable:**
* `id` (string, required): The unique ID of the product to delete.
* **Response:**
* **Status Code:** `204 No Content` If the product was successfully deleted.
* **Status Code:** `404 Not Found` If the product with the given ID does not exist.

### 4. Get a Product by ID (`GET /products/{id}`)

* **Description:** Retrieves a specific product based on its ID.
* **Path Variable:**
* `id` (string, required): The unique ID of the product to retrieve.
* **Response:**
* **Status Code:** `200 OK`
* **Response Body:** The `Product` object with the given ID.
```json
{
"id": "uniqueProductId",
"name": "Product Name",
"category": {
"categoryName": "Category Name"
},
"unitPrice": 10.0,
"expirationDate": "2025-12-31",
"inStock": 100,
"createdAt": "2025-05-29",
"updatedAt": null
}
```
* **Status Code:** `404 Not Found` If the product with the given ID does not exist.

### 5. Get All Products (with optional filters) (`GET /products`)

* **Description:** Retrieves a list of all products, with optional filtering by name, categories, and availability.
* **Query Parameters:**
* `name` (string, optional): Filters products whose name contains the provided string.
* `category` (string, optional): Filters products belonging to any of the provided category name.
* `inStock` (boolean, optional): Filters products based on their stock status (`true` for in-stock, `false` for out-of-stock and `null` for all products).
* **Response:**
* **Status Code:** `200 OK`
* **Response Body:** A list of `Product` objects.
```json
[
{
"id": "product1",
"name": "Product A",
"category": {
"categoryName": "Electronics"
},
"unitPrice": 10.00,
"expirationDate": null,
"inStock": 50,
"createdAt": "2025-05-29",
"updatedAt": null
},
{
"id": "product2",
"name": "Product B",
"category": {
"categoryName": "Books"
},
"unitPrice": 56.0,
"expirationDate": null,
"inStock": 0,
"createdAt": "2025-05-29",
"updatedAt": null
}
]
```

### 6. Mark Product as Out of Stock (`POST /products/{id}/outofstock`)

* **Description:** Marks a specific product as out of stock (sets `inStock` to 0).
* **Path Variable:**
* `id` (string, required): The unique ID of the product to update.
* **Response:**
* **Status Code:** `204 No Content` If the product was successfully marked as out of stock.
* **Status Code:** `404 Not Found` If the product with the given ID does not exist.

### 7. Mark Product as In Stock (`PUT /products/{id}/instock?defaultQuantity=10`)

* **Description:** Marks a specific product as in stock (sets `inStock` to 10).
* **Path Variable:**
* `id` (string, required): The unique ID of the product to update.
* **Response:**
* **Status Code:** `204 No Content` If the product was successfully marked as in stock.
* **Status Code:** `404 Not Found` If the product with the given ID does not exist.

### 8. Get Inventory Metrics Report (`GET /products/metrics`)

* **Description:** Retrieves a report containing overall inventory metrics and metrics per category.
* **Response:**
* **Status Code:** `200 OK`
* **Response Body:** An `InventoryMetricsReport` object.
```json
{
"categoryMetrics": [
{
"categoryName": "Books",
"totalProductsInStock": 5,
"totalValueInStock": 75.50,
"averagePriceInStock": 18.0
},
{
"categoryName": "Electronics",
"totalProductsInStock": 10,
"totalValueInStock": 50.00,
"averagePriceInStock": 5.00
}
],
"overallMetrics": {
"totalProductsInStock": 15,
"totalValueInStock": 30.0,
"averagePriceInStock": 20.0
}
}
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
package com.inventory.backend.model;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class InventoryMetricsTest {
@Test
void shouldComputerMetricsByCategoryCorrectly() {
Product p1 = new Product(UUID.randomUUID(), "Iteam A", "Alimentos", 10.0, 5, null);
Product p2 = new Product(UUID.randomUUID(), "Iteam B", "Alimentos", 15.0, 5, null);
Product p3 = new Product(UUID.randomUUID(), "Iteam C", "Electronica", 50.0, 10, null);

List<Product> products = List.of(p1,p2,p3);
InventoryMetrics metrics = InventoryMetrics.fromProductList(products);

assertEquals(20, metrics.getTotalInStock());
assertEquals(10.0, metrics.getByCategory().get("Alimentos").getAveragePrice());
assertEquals(100.0, metrics.getByCategory().get("Alimentos").getTotalValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ void shouldSortByNameAndStock() {
assertEquals(5, result.get(0).getQuantityInStock());
assertEquals(2, result.get(1).getQuantityInStock());
}

}
94 changes: 48 additions & 46 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
# Inventory Management FrontEnd

This is the front end for the inventory managment app, is used for managing products and categories with real-time data synchronization with a Spring Boot backend.


## **Product Management**
- **CRUD Operations** - Create, Read, Update, Delete products
- **Stock Management** - Toggle between in-stock and out-of-stock
- **Expiration Tracking** - Visual indicators for product expiration dates presented in colors
- **Category Assignment** - Organize products by categories with the possibility to filter them in base of their categories


## Tech Stack
- **Framework**: React 18
- **Language**: TypeScript 5
- **State Management**: React Context
- **Styling**: Tailwind CSS
- **HTTP Client**: Axios

## API Integration

### **Base Configuration**
```.env
REACT_APP_API_URL=http://localhost:9090
```
```typescript
// services/api.ts

const api = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});

export default api;
```

### **Product Endpoints**

| Method | Endpoint | Description | Request Body |
|--------|----------|-------------|--------------|
| `GET` | `/products` | Get all products with optional filters | Query params: `name`, `categories[]`, `inStock` |
| `GET` | `/products/{id}` | Get product by ID | - |
| `POST` | `/products` | Create new product | `ProductInfo` |
| `PUT` | `/products/{id}` | Update product | `ProductInfo` |
| `DELETE` | `/products/{id}` | Delete product | - |
| `POST` | `/products/{id}/outofstock` | Mark product as out of stock | - |
| `PUT` | `/products/{id}/instock?defaultQuantity=10` | Mark product as in stock | - |
| `GET` | `/products/metrics` | get metrics | - |
| `GET` | `/products/categories` | get all categories | - |
Loading