Skip to content

Week 5#76

Open
Pushkar06p wants to merge 31 commits into
Rippling:mainfrom
Pushkar06p:product-category-service-layer
Open

Week 5#76
Pushkar06p wants to merge 31 commits into
Rippling:mainfrom
Pushkar06p:product-category-service-layer

Conversation

@Pushkar06p

@Pushkar06p Pushkar06p commented Mar 27, 2026

Copy link
Copy Markdown

Summary

This PR implements the Product Category service layer, related APIs, and comprehensive test coverage. It also improves the development workflow by introducing automation via a Makefile and updating project documentation.


Features Implemented

  • Implemented ProductCategory service layer.

  • Added CRUD APIs for Product Categories.

  • Modeled relationship between Products and Categories.

  • Implemented APIs to:

    • Fetch products belonging to a category.
    • Add products to a category.
    • Remove products from a category.

Testing

  • Added unit tests for:

    • ProductCategoryService
    • ProductService
  • Mocked repository layers in unit tests.

  • Added seed scripts for integration testing.

  • Implemented integration tests for API endpoints.

  • Improved overall test coverage.

Run tests using:

make test

Run tests with coverage:

make coverage

Note

Medium Risk
Adds new MongoEngine-backed CRUD APIs plus category assignment endpoints and a MongoDB test harness, which can affect data integrity and request handling (notably multiple csrf_exempt views and new DB connection config). Workflow/docs changes are low risk, but the new backend surface area and DB integration raise overall risk.

Overview
Introduces new Django API surface for Products and Product Categories, including CRUD for categories and product endpoints to list, create, delete, fetch by id, list by category, and add/remove a category association.

Adds a MongoEngine data model layer (Product, ProductCategory) with repository/service abstractions, plus a migrate_brands management command and Django wiring (INSTALLED_APPS, URL includes, MongoDB connect() in settings.py).

Builds out automated dev/test workflow via a root Makefile, pytest configuration/fixtures for MongoDB-backed integration tests, coverage config (.coveragerc), and updates the root README.md to document setup/testing commands.

Written by Cursor Bugbot for commit 9595f08. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Comment @cursor review or bugbot run to trigger another review on this PR

Comment thread Makefile Outdated

# Run tests
test:
cd $(BACKEND_DIR) && $(PYTHON) -m pytest

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile test targets use wrong Python executable path

High Severity

The test, coverage, and html-coverage targets cd into $(BACKEND_DIR) but reference $(PYTHON) without the ../../ prefix. The backend target correctly uses ../../$(PYTHON) after the same cd, but these three targets don't, so the shell will look for venv\Scripts\python relative to backend\python instead of the repo root — causing the commands to fail with "file not found."

Additional Locations (2)
Fix in Cursor Fix in Web

if product:
product.category = category
product.save()
return product

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding category silently clears it when category missing

Medium Severity

add_category_to_product looks up the category by ID, but if category_id doesn't match any existing category, category is None. The code then assigns None to product.category and saves, silently removing the product's existing category instead of reporting an error. The service layer only validates that the product exists, not the category.

Fix in Cursor Fix in Web

Comment thread backend/python/warehouse/views.py Outdated

# Create product
new_product = {
"id": storage.CURRENT_ID + 1,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Off-by-one error in warehouse product ID generation

Low Severity

CURRENT_ID starts at 1 in storage.py, but the new product ID is computed as storage.CURRENT_ID + 1 before incrementing. This means the first product gets ID 2 instead of 1, and all subsequent IDs are similarly shifted. Either CURRENT_ID needs to start at 0, or the ID assignment needs to use CURRENT_ID directly (incrementing afterward).

Additional Locations (1)
Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant