From 036fae4ac2256253db32036e8f550e3a7d3eeda4 Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 26 Jun 2025 14:39:02 -0600 Subject: [PATCH 1/5] feat: added new tests --- .../backend/model/InventoryMetricsTest.java | 20 +++++++++++++++++++ .../backend/service/ProductServiceTest.java | 1 + 2 files changed, 21 insertions(+) diff --git a/backend/src/test/java/com/inventory/backend/model/InventoryMetricsTest.java b/backend/src/test/java/com/inventory/backend/model/InventoryMetricsTest.java index d415d11..aef7021 100644 --- a/backend/src/test/java/com/inventory/backend/model/InventoryMetricsTest.java +++ b/backend/src/test/java/com/inventory/backend/model/InventoryMetricsTest.java @@ -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 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()); + } } diff --git a/backend/src/test/java/com/inventory/backend/service/ProductServiceTest.java b/backend/src/test/java/com/inventory/backend/service/ProductServiceTest.java index 507be27..9cb6e36 100644 --- a/backend/src/test/java/com/inventory/backend/service/ProductServiceTest.java +++ b/backend/src/test/java/com/inventory/backend/service/ProductServiceTest.java @@ -127,4 +127,5 @@ void shouldSortByNameAndStock() { assertEquals(5, result.get(0).getQuantityInStock()); assertEquals(2, result.get(1).getQuantityInStock()); } + } From 35d476b169499f24ad62b6946573ea7c0a7569fd Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 26 Jun 2025 14:50:48 -0600 Subject: [PATCH 2/5] fix: updated frontend readme --- frontend/README.md | 94 +++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/frontend/README.md b/frontend/README.md index b87cb00..feb2a0a 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -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**: Next.js 14 (App Router) +- **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 | - | \ No newline at end of file From d73bd723177b4a163966c4474d874a9be9aa2bfb Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 26 Jun 2025 14:53:42 -0600 Subject: [PATCH 3/5] fix: changes to the readme --- frontend/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/README.md b/frontend/README.md index feb2a0a..fbb2120 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -11,7 +11,7 @@ This is the front end for the inventory managment app, is used for managing prod ## Tech Stack -- **Framework**: Next.js 14 (App Router) +- **Framework**: React 18 - **Language**: TypeScript 5 - **State Management**: React Context - **Styling**: Tailwind CSS From cc292dd15b01c76f624a57ba15202153aeab39e5 Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 26 Jun 2025 15:03:07 -0600 Subject: [PATCH 4/5] fix: updated backend README --- backend/README.md | 175 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 backend/README.md diff --git a/backend/README.md b/backend/README.md new file mode 100644 index 0000000..0ab7417 --- /dev/null +++ b/backend/README.md @@ -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 (`PUT /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 + } + } + ``` \ No newline at end of file From e6ca201b3e64ec72d3c65c40c318b72b76efdf51 Mon Sep 17 00:00:00 2001 From: Francisco Castillo Date: Thu, 26 Jun 2025 15:04:40 -0600 Subject: [PATCH 5/5] Update README.md --- backend/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/README.md b/backend/README.md index 0ab7417..f24339a 100644 --- a/backend/README.md +++ b/backend/README.md @@ -126,7 +126,7 @@ This controller provides endpoints for managing product information. ] ``` -### 6. Mark Product as Out of Stock (`PUT /products/{id}/outofstock`) +### 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:** @@ -172,4 +172,4 @@ This controller provides endpoints for managing product information. "averagePriceInStock": 20.0 } } - ``` \ No newline at end of file + ```