from typing import List from ninja import Router from .models import Game from .schemas import GameOut, PlanningSlotOut, SteamGameOut from .services.planning import planning_with_games from .tasks import schedule_steam_refresh router = Router() event_router = Router() @router.get("", response=List[GameOut]) def list_games(request): return Game.objects.all() @event_router.get("/events/{event_path}/games", response=List[GameOut]) def list_event_games(request, event_path: str): return Game.objects.enabled_for_event(request.event) @event_router.get("/events/{event_path}/games/steam", response=List[SteamGameOut]) def list_event_steam_games(request, event_path: str): """The event's Steam games with their store info (price, discount, blurb).""" # Safety net in case the periodic refresh loop isn't running (no-op otherwise). schedule_steam_refresh() return Game.objects.enabled_for_event(request.event).filter( steam_app_id__isnull=False ) @event_router.get("/events/{event_path}/planning", response=List[PlanningSlotOut]) def list_event_planning(request, event_path: str): """The event planning, with the covers of the games we know.""" return planning_with_games(request.event.planning_slots.all())