Skip to content

Added filtering games by location (on/off-campus)#68

Open
andrewp0809 wants to merge 2 commits intomasterfrom
andrew/query_by_campus_filter
Open

Added filtering games by location (on/off-campus)#68
andrewp0809 wants to merge 2 commits intomasterfrom
andrew/query_by_campus_filter

Conversation

@andrewp0809
Copy link

@andrewp0809 andrewp0809 commented Mar 22, 2026

##Overview

Added support for filtering games by on-campus vs off-campus locations through a new GraphQL query. This allows clients to easily retrieve games based on whether they are played in Ithaca (on-campus) or elsewhere.

##Changes Made

Implemented a new repository method find_by_location(onCampus) that queries MongoDB using:

"city": "Ithaca" for on-campus games

"city": { "$ne": "Ithaca" } for off-campus games

##Test Coverage
Manual Testing, ran GraphQL queries in GraphiQL.

Summary by CodeRabbit

  • New Features

    • Users can now filter games by location type—either on-campus or off-campus events—making it easier to discover games matching their geographic preferences.
  • Chores

    • Enhanced database performance with indexing optimizations.

@coderabbitai
Copy link

coderabbitai bot commented Mar 22, 2026

📝 Walkthrough

Walkthrough

This pull request introduces a location-based game filtering feature by adding a MongoDB index on the city field, a new GraphQL query field games_by_location that accepts an onCampus boolean argument, and corresponding service and repository methods that delegate queries to filter games based on whether they are located in Ithaca.

Changes

Cohort / File(s) Summary
Database Setup
src/database.py
Added MongoDB background index on city field of game_collection to optimize location-based queries.
GraphQL API
src/queries/game_query.py
Added games_by_location query field with required onCampus boolean argument and corresponding resolver; imported Boolean type from Graphene.
Data Access Layer
src/repositories/game_repository.py, src/services/game_service.py
Added find_by_location(onCampus) repository method that queries games by city ("Ithaca" for on-campus, non-"Ithaca" for off-campus) and get_games_by_location(onCampus) service method that delegates to the repository.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client
    participant GraphQL as GraphQL Query
    participant Service as GameService
    participant Repo as GameRepository
    participant DB as MongoDB

    Client->>GraphQL: Query games_by_location(onCampus=true)
    GraphQL->>GraphQL: resolve_games_by_location(onCampus)
    GraphQL->>Service: get_games_by_location(onCampus)
    Service->>Repo: find_by_location(onCampus)
    Repo->>DB: Query: city == "Ithaca" OR city != "Ithaca"
    DB-->>Repo: Return matching Game documents
    Repo-->>Service: Return List[Game]
    Service-->>GraphQL: Return List[Game]
    GraphQL-->>Client: Return games filtered by location
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A fluffy tale of cities near and far,
Where games align beneath each star,
Ithaca gleams on campus bright,
While distant fields dance out of sight,
One query filters with a Boolean's care—
Location magic blooms in the air!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a new filtering capability for games by location (on/off-campus), which matches the core objective of the pull request.
Description check ✅ Passed The description covers the main sections (Overview and Changes Made) and includes testing information, though Test Coverage section lacks specific reproduction steps or testing details beyond 'Manual Testing in GraphiQL'.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch andrew/query_by_campus_filter

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
src/queries/game_query.py (1)

33-33: Consider adding a description to the onCampus argument.

Other fields in this class don't have argument descriptions either, but for clarity, consider documenting what onCampus means (e.g., games in Ithaca vs. away games):

games_by_location = List(
    GameType, 
    onCampus=Boolean(required=True, description="True for games in Ithaca, False for away games")
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/queries/game_query.py` at line 33, Add a description to the onCampus
argument on the games_by_location field so callers know its meaning: update the
games_by_location declaration (the List[GameType] field named games_by_location)
to include a description on the onCampus=Boolean(...) argument (e.g., "True for
games in Ithaca, False for away games") so the schema docs clearly convey what
onCampus represents.
src/repositories/game_repository.py (2)

250-251: Consider using snake_case for parameter naming.

The parameter onCampus uses camelCase, which differs from Python naming conventions (snake_case). While this matches the GraphQL API naming, Python methods typically use on_campus. This is a minor consistency issue.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/repositories/game_repository.py` around lines 250 - 251, Rename the
parameter onCampus to on_campus in the find_by_location static method and update
all internal references inside find_by_location and any callers to use the new
snake_case name; if the method is part of a public API that must accept
camelCase (e.g., GraphQL resolver), add a thin adapter that maps the incoming
onCampus argument to the on_campus parameter before calling
GameRepository.find_by_location to preserve external compatibility. Ensure the
function signature and all variable references use on_campus and update any unit
tests or call sites accordingly.

259-262: Extract hardcoded city value to constant and fix null city handling in off-campus query.

Two refactoring recommendations:

  1. The city value "Ithaca" is hardcoded. Extract it to a module-level constant for maintainability.

  2. When onCampus=False, the $ne operator will match documents where city is null or missing. If games with unknown locations should be excluded from off-campus results (consistent with how null cities are explicitly handled in find_by_exact_match), use $exists: true and $ne:

♻️ Suggested approach
+CAMPUS_CITY = "Ithaca"
+
 `@staticmethod`
 def find_by_location(onCampus):
     ...
     if onCampus:
-        query = {"city": "Ithaca"}
+        query = {"city": CAMPUS_CITY}
      else:
-        query = {"city": {"$ne": "Ithaca"}}
+        query = {"city": {"$ne": CAMPUS_CITY, "$exists": true}}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/repositories/game_repository.py` around lines 259 - 262, Extract the
hardcoded "Ithaca" into a module-level constant (e.g., CAMPUS_CITY or
CITY_ITHACA) and use that constant when building the query; then change the
off-campus branch that currently sets query = {"city": {"$ne": "Ithaca"}} to
exclude documents with missing/null cities by using both $exists and $ne (e.g.,
{"city": {"$exists": True, "$ne": CITY_ITHACA}}), matching the null-handling
used in find_by_exact_match; update any references to the literal string in this
module to use the new constant.
src/services/game_service.py (1)

123-128: Consider adding pagination for large result sets.

This method can return all games matching the location filter without limits. While this is consistent with similar methods like get_games_by_sport and get_games_by_gender, consider adding optional limit and offset parameters (similar to get_all_games) to prevent unbounded result sets in production.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/game_service.py` around lines 123 - 128, get_games_by_location
currently returns all matching rows; change the signature of
GameService.get_games_by_location to accept optional pagination parameters
(e.g., limit and offset with sensible defaults) and pass them through to
GameRepository.find_by_location (update that method signature too) so the DB
query can apply LIMIT/OFFSET; update any callers of get_games_by_location to
provide or honor the new params and ensure behavior matches
get_all_games/get_games_by_sport patterns.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/queries/game_query.py`:
- Line 33: Add a description to the onCampus argument on the games_by_location
field so callers know its meaning: update the games_by_location declaration (the
List[GameType] field named games_by_location) to include a description on the
onCampus=Boolean(...) argument (e.g., "True for games in Ithaca, False for away
games") so the schema docs clearly convey what onCampus represents.

In `@src/repositories/game_repository.py`:
- Around line 250-251: Rename the parameter onCampus to on_campus in the
find_by_location static method and update all internal references inside
find_by_location and any callers to use the new snake_case name; if the method
is part of a public API that must accept camelCase (e.g., GraphQL resolver), add
a thin adapter that maps the incoming onCampus argument to the on_campus
parameter before calling GameRepository.find_by_location to preserve external
compatibility. Ensure the function signature and all variable references use
on_campus and update any unit tests or call sites accordingly.
- Around line 259-262: Extract the hardcoded "Ithaca" into a module-level
constant (e.g., CAMPUS_CITY or CITY_ITHACA) and use that constant when building
the query; then change the off-campus branch that currently sets query =
{"city": {"$ne": "Ithaca"}} to exclude documents with missing/null cities by
using both $exists and $ne (e.g., {"city": {"$exists": True, "$ne":
CITY_ITHACA}}), matching the null-handling used in find_by_exact_match; update
any references to the literal string in this module to use the new constant.

In `@src/services/game_service.py`:
- Around line 123-128: get_games_by_location currently returns all matching
rows; change the signature of GameService.get_games_by_location to accept
optional pagination parameters (e.g., limit and offset with sensible defaults)
and pass them through to GameRepository.find_by_location (update that method
signature too) so the DB query can apply LIMIT/OFFSET; update any callers of
get_games_by_location to provide or honor the new params and ensure behavior
matches get_all_games/get_games_by_sport patterns.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5d67e7e3-c0dd-42ba-bddc-db32c6486330

📥 Commits

Reviewing files that changed from the base of the PR and between c57a11d and c41f439.

📒 Files selected for processing (4)
  • src/database.py
  • src/queries/game_query.py
  • src/repositories/game_repository.py
  • src/services/game_service.py

taskflowdev1

This comment was marked as spam.

Copy link
Contributor

@JoshD94 JoshD94 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@claiireyu claiireyu left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Contributor

@AnikDey-exe AnikDey-exe left a comment

Choose a reason for hiding this comment

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

looks good to me

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.

5 participants