Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([("city", 1)], background=True)

# Create compound indexes for common query combinations
game_collection.create_index([("sport", 1), ("gender", 1)], background=True)
Expand Down
10 changes: 9 additions & 1 deletion src/queries/game_query.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
18 changes: 18 additions & 0 deletions src/repositories/game_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@ 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"]

if onCampus:
query = {"city": "Ithaca"}
else:
query = {"city": {"$ne": "Ithaca"}}

games = game_collection.find(query)

return [Game.from_dict(game) for game in games]

@staticmethod
def find_by_ids(game_ids):
Expand Down
7 changes: 7 additions & 0 deletions src/services/game_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
Loading