Skip to content

Implement Discount Code Functionality in Shopping Bag #4

@sennap

Description

@sennap

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:

  1. Basket.API:

    • New discount validation endpoint
    • CQRS command/handler implementation
    • Discount service interface and implementation
    • Unit tests for new functionality
  2. Frontend:

    • Shopping bag component modifications
    • New discount code input component
    • Updated total calculation logic

Implementation Steps

Backend Implementation

  1. Create IDiscountService interface and implementation
  2. Implement CQRS command/handler for discount validation
  3. Add discount validation endpoint to Basket.API
  4. Add proper error handling and validation
  5. Implement unit tests for new functionality

Frontend Implementation

  1. Create discount code input component
  2. Update shopping bag component to include discount functionality
  3. Implement discount application logic
  4. Add error handling and validation
  5. Update total calculation to include discounts
  6. 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

  1. Unit Tests:

    • Discount validation logic
    • Total calculation with discounts
    • Error handling scenarios
  2. Integration Tests:

    • API endpoint testing
    • Frontend-backend integration
    • Error scenarios
  3. E2E Tests:

    • Discount application flow
    • Error handling
    • UI responsiveness

Acceptance Criteria

  1. Users can enter discount codes in the shopping bag
  2. Invalid codes show appropriate error messages
  3. Valid codes update the total price immediately
  4. Loading states are shown during validation
  5. Error messages are clear and user-friendly
  6. Discount codes are properly validated on the backend
  7. Changes follow existing architecture patterns
  8. Full test coverage for new functionality
  9. Proper error handling throughout the flow
  10. Follows Microsoft's .NET coding conventions and accessibility standards

Dependencies

  • Basket.API service
  • Frontend shopping bag components
  • CQRS/MediatR infrastructure
  • Testing infrastructure

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions