forked from dotnet/eShop
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Discount Code Implementation Plan
Overview
Add discount code functionality to the shopping bag page allowing users to enter and apply discount codes that will update the checkout price or show appropriate error messages.
Current Implementation Analysis
Architecture Context
- Uses CQRS pattern with MediatR for commands/queries
- Part of the Basket.API service which handles shopping cart functionality
- Frontend implementations in Web and Client applications
Impact Analysis
Files requiring modification:
-
Basket.API:
- New discount validation endpoint
- CQRS command/handler implementation
- Discount service interface and implementation
- Unit tests for new functionality
-
Frontend:
- Shopping bag component modifications
- New discount code input component
- Updated total calculation logic
Implementation Steps
Backend Implementation
- Create IDiscountService interface and implementation
- Implement CQRS command/handler for discount validation
- Add discount validation endpoint to Basket.API
- Add proper error handling and validation
- Implement unit tests for new functionality
Frontend Implementation
- Create discount code input component
- Update shopping bag component to include discount functionality
- Implement discount application logic
- Add error handling and validation
- Update total calculation to include discounts
- Add appropriate loading states and error messages
Security Considerations
- Input validation for discount codes
- Rate limiting for discount validation endpoint
- Proper error handling to prevent information leakage
- Authorization checks for discount application
Testing Requirements
-
Unit Tests:
- Discount validation logic
- Total calculation with discounts
- Error handling scenarios
-
Integration Tests:
- API endpoint testing
- Frontend-backend integration
- Error scenarios
-
E2E Tests:
- Discount application flow
- Error handling
- UI responsiveness
Acceptance Criteria
- Users can enter discount codes in the shopping bag
- Invalid codes show appropriate error messages
- Valid codes update the total price immediately
- Loading states are shown during validation
- Error messages are clear and user-friendly
- Discount codes are properly validated on the backend
- Changes follow existing architecture patterns
- Full test coverage for new functionality
- Proper error handling throughout the flow
- Follows Microsoft's .NET coding conventions and accessibility standards
Dependencies
- Basket.API service
- Frontend shopping bag components
- CQRS/MediatR infrastructure
- Testing infrastructure