From 017ed0534c62062da4d897643f912cc4cd050241 Mon Sep 17 00:00:00 2001 From: andrewp0809 Date: Wed, 11 Mar 2026 18:27:19 -0400 Subject: [PATCH 1/2] Implement direct filtering on location --- src/database.py | 1 + src/queries/game_query.py | 10 +++++++++- src/repositories/game_repository.py | 23 +++++++++++++++++++++++ src/services/game_service.py | 7 +++++++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/database.py b/src/database.py index 20f1331..0bc0fa8 100644 --- a/src/database.py +++ b/src/database.py @@ -62,6 +62,7 @@ def setup_database_indexes(): game_collection.create_index([("sport", 1)], background=True) game_collection.create_index([("date", 1)], background=True) game_collection.create_index([("gender", 1)], background=True) + game_collection.create_index([("location", 1)], background=True) # Create compound indexes for common query combinations game_collection.create_index([("sport", 1), ("gender", 1)], background=True) diff --git a/src/queries/game_query.py b/src/queries/game_query.py index 5842d05..9343e2f 100644 --- a/src/queries/game_query.py +++ b/src/queries/game_query.py @@ -1,6 +1,6 @@ from bson import ObjectId from flask_jwt_extended import get_jwt_identity, jwt_required -from graphene import ObjectType, String, Field, List, Int, DateTime +from graphene import Boolean, ObjectType, String, Field, List, Int, DateTime from src.database import db from src.services.game_service import GameService from src.types import GameType @@ -30,6 +30,7 @@ class GameQuery(ObjectType): GameType, sport=String(required=True), gender=String(required=True) ) games_by_date = List(GameType, startDate=DateTime(required=True), endDate=DateTime(required=True)) + games_by_location = List(GameType, onCampus=Boolean(required=True)) my_favorited_games = List(GameType, description="Current user's favorited games (requires auth).") @jwt_required() @@ -88,3 +89,10 @@ def resolve_games_by_date(self, info, startDate, endDate): Resolver for retrieving games by date. """ return GameService.get_games_by_date(startDate, endDate) + + + def resolve_games_by_location(self, info, onCampus): + """ + Resolver for retrieving games by location. + """ + return GameService.get_games_by_location(onCampus) diff --git a/src/repositories/game_repository.py b/src/repositories/game_repository.py index e531286..e305549 100644 --- a/src/repositories/game_repository.py +++ b/src/repositories/game_repository.py @@ -246,6 +246,29 @@ def find_by_date(startDate, endDate): games = game_collection.find(query) return [Game.from_dict(game) for game in games] + + @staticmethod + def find_by_location(onCampus): + """ + Retrieve all games from the 'game' collection in MongoDB where + "onCampus" boolean indicates location is on campus (true) or + off campus (false). + """ + game_collection = db["game"] + + CAMPUS_LOCATIONS = [ + "Ithaca, NY", + "Lynah Rink" + ] + + if onCampus: + query = {"location": {"$in": CAMPUS_LOCATIONS}} + else: + query = {"location": {"$nin": CAMPUS_LOCATIONS}} + + games = game_collection.find(query) + + return [Game.from_dict(game) for game in games] @staticmethod def find_by_ids(game_ids): diff --git a/src/services/game_service.py b/src/services/game_service.py index 6fd3479..c7c4721 100644 --- a/src/services/game_service.py +++ b/src/services/game_service.py @@ -120,6 +120,13 @@ def get_games_by_date(startDate, endDate): """ return GameRepository.find_by_date(startDate, endDate) + @staticmethod + def get_games_by_location(onCampus): + """ + Retrieves all games by their location. + """ + return GameRepository.find_by_location(onCampus) + @staticmethod def get_tournament_games_by_sport_gender(sport, gender, after_date=None): """ From c41f4390b2796a69f04f43c8933822a74f600aa0 Mon Sep 17 00:00:00 2001 From: andrewp0809 Date: Wed, 18 Mar 2026 18:31:16 -0400 Subject: [PATCH 2/2] Add correct city filtering --- src/database.py | 2 +- src/repositories/game_repository.py | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/database.py b/src/database.py index 0bc0fa8..753dfc7 100644 --- a/src/database.py +++ b/src/database.py @@ -62,7 +62,7 @@ def setup_database_indexes(): game_collection.create_index([("sport", 1)], background=True) game_collection.create_index([("date", 1)], background=True) game_collection.create_index([("gender", 1)], background=True) - game_collection.create_index([("location", 1)], background=True) + game_collection.create_index([("city", 1)], background=True) # Create compound indexes for common query combinations game_collection.create_index([("sport", 1), ("gender", 1)], background=True) diff --git a/src/repositories/game_repository.py b/src/repositories/game_repository.py index e305549..62a19d2 100644 --- a/src/repositories/game_repository.py +++ b/src/repositories/game_repository.py @@ -256,15 +256,10 @@ def find_by_location(onCampus): """ game_collection = db["game"] - CAMPUS_LOCATIONS = [ - "Ithaca, NY", - "Lynah Rink" - ] - if onCampus: - query = {"location": {"$in": CAMPUS_LOCATIONS}} + query = {"city": "Ithaca"} else: - query = {"location": {"$nin": CAMPUS_LOCATIONS}} + query = {"city": {"$ne": "Ithaca"}} games = game_collection.find(query)