Add version groups to share routes and boss battles across games
Routes and boss battles now belong to a version_group instead of individual games, so paired versions (e.g. Red/Blue, Gold/Silver) share the same route structure and boss battles. Route encounters gain a game_id column to support game-specific encounter tables within a shared route. Includes migration, updated seeds, API changes, and frontend type updates. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,15 @@ from app.schemas.boss import (
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
async def _get_version_group_id(session: AsyncSession, game_id: int) -> int:
|
||||
game = await session.get(Game, game_id)
|
||||
if game is None:
|
||||
raise HTTPException(status_code=404, detail="Game not found")
|
||||
if game.version_group_id is None:
|
||||
raise HTTPException(status_code=400, detail="Game has no version group assigned")
|
||||
return game.version_group_id
|
||||
|
||||
|
||||
# --- Game-scoped (admin) endpoints ---
|
||||
|
||||
|
||||
@@ -30,13 +39,11 @@ router = APIRouter()
|
||||
async def list_bosses(
|
||||
game_id: int, session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
game = await session.get(Game, game_id)
|
||||
if game is None:
|
||||
raise HTTPException(status_code=404, detail="Game not found")
|
||||
vg_id = await _get_version_group_id(session, game_id)
|
||||
|
||||
result = await session.execute(
|
||||
select(BossBattle)
|
||||
.where(BossBattle.game_id == game_id)
|
||||
.where(BossBattle.version_group_id == vg_id)
|
||||
.options(selectinload(BossBattle.pokemon).selectinload(BossPokemon.pokemon))
|
||||
.order_by(BossBattle.order)
|
||||
)
|
||||
@@ -49,11 +56,9 @@ async def create_boss(
|
||||
data: BossBattleCreate,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
game = await session.get(Game, game_id)
|
||||
if game is None:
|
||||
raise HTTPException(status_code=404, detail="Game not found")
|
||||
vg_id = await _get_version_group_id(session, game_id)
|
||||
|
||||
boss = BossBattle(game_id=game_id, **data.model_dump())
|
||||
boss = BossBattle(version_group_id=vg_id, **data.model_dump())
|
||||
session.add(boss)
|
||||
await session.commit()
|
||||
|
||||
@@ -73,9 +78,11 @@ async def update_boss(
|
||||
data: BossBattleUpdate,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
vg_id = await _get_version_group_id(session, game_id)
|
||||
|
||||
result = await session.execute(
|
||||
select(BossBattle)
|
||||
.where(BossBattle.id == boss_id, BossBattle.game_id == game_id)
|
||||
.where(BossBattle.id == boss_id, BossBattle.version_group_id == vg_id)
|
||||
.options(selectinload(BossBattle.pokemon).selectinload(BossPokemon.pokemon))
|
||||
)
|
||||
boss = result.scalar_one_or_none()
|
||||
@@ -103,8 +110,10 @@ async def delete_boss(
|
||||
boss_id: int,
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
vg_id = await _get_version_group_id(session, game_id)
|
||||
|
||||
result = await session.execute(
|
||||
select(BossBattle).where(BossBattle.id == boss_id, BossBattle.game_id == game_id)
|
||||
select(BossBattle).where(BossBattle.id == boss_id, BossBattle.version_group_id == vg_id)
|
||||
)
|
||||
boss = result.scalar_one_or_none()
|
||||
if boss is None:
|
||||
@@ -125,9 +134,11 @@ async def set_boss_team(
|
||||
team: list[BossPokemonInput],
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
vg_id = await _get_version_group_id(session, game_id)
|
||||
|
||||
result = await session.execute(
|
||||
select(BossBattle)
|
||||
.where(BossBattle.id == boss_id, BossBattle.game_id == game_id)
|
||||
.where(BossBattle.id == boss_id, BossBattle.version_group_id == vg_id)
|
||||
.options(selectinload(BossBattle.pokemon))
|
||||
)
|
||||
boss = result.scalar_one_or_none()
|
||||
|
||||
Reference in New Issue
Block a user