added cart functionallity#1
Conversation
There was a problem hiding this comment.
Pull Request Overview
Implements shopping cart functionality across the full stack, enabling users to add products to cart, view cart contents, and remove items from cart while managing inventory stock.
- Added cart data models and API endpoints for cart operations (add, get, remove)
- Created shopping cart UI component with floating cart display and item management
- Updated product cards to include "Add to Cart" functionality with stock validation
Reviewed Changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| 04_market/src/types/cart.ts | Defines TypeScript interfaces for cart items and cart creation requests |
| 04_market/src/pages/ProductsPage.tsx | Integrates shopping cart component and handles cart refresh state |
| 04_market/src/components/ShoppingCart.tsx | Implements floating shopping cart UI with item display and removal |
| 04_market/src/components/ShoppingCart.css | Styles for the floating shopping cart component |
| 04_market/src/components/ProductCard.tsx | Adds "Add to Cart" button with stock validation and error handling |
| 04_market/src/api/cartRequests.ts | API client functions for cart operations (add, get, remove) |
| 03_python_fastapi_project/test_cart.py | Test script for cart functionality (hardcoded path) |
| 03_python_fastapi_project/main.py | Backend cart API endpoints with inventory management |
| 03_python_fastapi_project/database.py | Database model for cart items with foreign key relationship |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| await removeFromCart(cartItemId); | ||
| await loadCart(); | ||
| // Refresh the page to update product stock | ||
| window.location.reload(); |
There was a problem hiding this comment.
Using window.location.reload() is a heavy-handed approach that causes a full page refresh. Consider using the existing cart refresh mechanism or state management instead.
| if (onCartUpdate) { | ||
| onCartUpdate(); | ||
| } | ||
| navigate(0); // Refresh to update stock |
There was a problem hiding this comment.
Using navigate(0) causes a full page refresh. Consider updating the product state locally or using a proper state management solution to avoid the jarring user experience.
| class CartItemCreate(BaseModel): | ||
| product_id: int | ||
| quantity: int = 1 |
There was a problem hiding this comment.
Missing input validation for quantity field. Should validate that quantity is positive and within reasonable limits.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.