Skip to content

Add game filtering by publisher and category#17

Open
GeekTrainer wants to merge 3 commits into
mainfrom
feature/game-filtering
Open

Add game filtering by publisher and category#17
GeekTrainer wants to merge 3 commits into
mainfrom
feature/game-filtering

Conversation

@GeekTrainer

Copy link
Copy Markdown
Owner

Summary

A user reported that they were unable to filter games by publisher and category. After investigation, this functionality did not exist. This PR implements game filtering to allow users to filter the games list by publisher and/or category.

Changes

  • Added query parameter filtering to /api/games endpoint
  • Added /api/publishers and /api/categories endpoints for filter dropdowns
  • Created GameFilters.svelte component with publisher/category dropdowns
  • Integrated filters into GameList.svelte
  • Added comprehensive backend and E2E tests

Backend API Changes

The /api/games endpoint now accepts optional query parameters:

GET /api/games?publisher_id=1&category_id=2

New endpoints for filter options:

  • GET /api/publishers - Returns all publishers
  • GET /api/categories - Returns all categories

Code snippet

@games_bp.route('/api/games', methods=['GET'])
def get_games() -> Response:
    """Get all games with optional filtering by publisher_id and category_id."""
    query = get_games_base_query()
    
    publisher_id = request.args.get('publisher_id', type=int)
    if publisher_id is not None:
        query = query.filter(Game.publisher_id == publisher_id)
    
    category_id = request.args.get('category_id', type=int)
    if category_id is not None:
        query = query.filter(Game.category_id == category_id)
    
    games_query = query.all()
    return jsonify([game.to_dict() for game in games_query])

Frontend Changes

New GameFilters.svelte component with:

  • Publisher dropdown filter
  • Category dropdown filter
  • Clear filters button (appears when filters are active)
  • Accessible labels and keyboard navigation

Testing

  • Backend: 8 new unit tests (19 total passing)
  • E2E: 8 new Playwright tests (28 total passing)

Test coverage includes:

  • Filtering by publisher only
  • Filtering by category only
  • Filtering by both publisher and category
  • Clear filters functionality
  • Empty state when no results match
  • Accessibility of filter controls

- Add publisher_id and category_id query parameters to /api/games
- Add /api/publishers endpoint for filter dropdown
- Add /api/categories endpoint for filter dropdown
- Add unit tests for filtering functionality
- Create GameFilters.svelte with publisher/category dropdowns
- Integrate filters into GameList.svelte
- Add clear filters functionality
- Include data-testid attributes for testability
- Test filter controls visibility and accessibility
- Test filtering by publisher and category
- Test clear filters functionality
- Test combined filter scenarios
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.

1 participant