Skip to content

Add product categorization feature - #40

Open
devin-ai-integration[bot] wants to merge 4 commits into
mainfrom
devin/1763139020-add-product-categories
Open

devin-ai-integration[bot] wants to merge 4 commits into
mainfrom
devin/1763139020-add-product-categories

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Add product categorization feature

Summary

This PR adds comprehensive product categorization capabilities to the inventory management system, enabling better organization and filtering of products by category.

Backend changes:

  • Created Category entity with JPA annotations (id, name, description)
  • Added ManyToOne relationship from Product to Category (nullable foreign key)
  • Implemented full CRUD REST API at /api/categories via CategoryController
  • Added CategoryService and CategoryRepository following existing patterns
  • Extended ProductController with /api/products/category/{categoryId} endpoint for filtering
  • Updated DataInitializer to create 4 sample categories (Electronics, Computers, Audio, Wearables) and assign them to existing products

Frontend changes:

  • Created new CategoryList component with interactive category cards and product filtering
  • Updated Dashboard to display total category count as a new stat card
  • Added "Categories" navigation link to sidebar with tags icon
  • Extended API service with 6 new category-related functions
  • Added routing for /categories path in App.js

Testing:

  • Backend compilation: ✅ Passed
  • Frontend build: ✅ Passed (1 pre-existing warning unrelated to this PR)
  • Backend tests: ✅ All 5 tests passing

Review & Testing Checklist for Human

⚠️ Risk Level: YELLOW - Database schema changes with limited end-to-end testing

  • Test full category workflow in browser: Navigate to http://localhost:3000/categories, verify categories display correctly, click on each category to filter products, verify products show up correctly for each category
  • Verify database behavior: Check what happens when you try to delete a category that has products assigned to it (should fail with foreign key constraint or handle gracefully)
  • Test Dashboard integration: Verify the new "Product Categories" stat card displays the correct count (should show 4 after initialization)
  • Check existing product handling: Verify that products without an assigned category still display properly in the product list (category is nullable)

Notes

  • Database schema change: This PR adds a new categories table and a category_id foreign key column to the products table. The relationship is nullable, so existing products without categories are supported.
  • No explicit migration scripts: JPA/Hibernate auto-creates the schema in dev (H2), but production deployments may need explicit migration scripts (Flyway/Liquibase).
  • Cascade behavior: Category deletion does not cascade to products - attempting to delete a category with products will likely fail with a foreign key constraint violation. This may need explicit handling in a future PR.
  • Sample data: DataInitializer creates 4 categories and assigns them to the 5 sample products on first run.

Session: https://app.devin.ai/sessions/04a702452ace48b1a011a37aa9da125e
Requested by: mason.batchelor@cognition.ai (@mbatchelor81)

- Created Category entity with id, name, and description fields
- Added ManyToOne relationship between Product and Category
- Implemented CategoryRepository, CategoryService, and CategoryController
- Added category filtering endpoints to ProductController and ProductService
- Updated DataInitializer to create sample categories and assign to products
- Created frontend CategoryList component for viewing categories and filtering products
- Updated Dashboard to display category statistics
- Added Categories navigation link to Layout
- Updated frontend API service with category endpoints
- All backend tests passing

Co-Authored-By: mason.batchelor@cognition.ai <masonbatchelor81@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration Bot and others added 3 commits November 14, 2025 17:07
- Refactor CategoryController to use helper methods, reducing duplication from 7.86% to below 3%
- Add CategoryServiceTest with 13 test cases covering all CRUD operations
- Add CategoryControllerTest with 11 MockMvc test cases for REST endpoints
- Add ProductServiceTest.testGetProductsByCategoryReturnsMatchingProducts
- All 30 tests passing successfully
- Addresses SonarQube quality gate failures for coverage and duplication

Co-Authored-By: mason.batchelor@cognition.ai <masonbatchelor81@gmail.com>
- Extract okOrNotFound helper method for Optional to ResponseEntity mapping
- Reduces repeated .map(ResponseEntity::ok).orElse(ResponseEntity.notFound().build()) pattern
- Addresses remaining SonarQube duplication issue (3.14% -> target <3%)

Co-Authored-By: mason.batchelor@cognition.ai <masonbatchelor81@gmail.com>
- Removes 8 duplicate lines that were matching Product.java pattern
- No usage of Category.toString() found in codebase
- Addresses SonarQube duplication issue (3.13% -> target <3%)
- All 30 tests passing

Co-Authored-By: mason.batchelor@cognition.ai <masonbatchelor81@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants