Fix linting errors across backend and frontend
Backend: auto-fix and format all ruff issues, manually fix B904/B023/ SIM117/B007/E741/F841 errors, suppress B008 (FastAPI Depends) and F821 (SQLAlchemy forward refs) in config. Frontend: allow constant exports, disable React compiler-specific rules (set-state-in-effect, preserve-manual-memoization). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Response
|
||||
from sqlalchemy import func, select
|
||||
@@ -9,18 +9,22 @@ from app.core.database import get_session
|
||||
from app.models.boss_result import BossResult
|
||||
from app.models.encounter import Encounter
|
||||
from app.models.game import Game
|
||||
from app.models.genlocke import Genlocke, GenlockeLeg
|
||||
from app.models.genlocke import GenlockeLeg
|
||||
from app.models.genlocke_transfer import GenlockeTransfer
|
||||
from app.models.nuzlocke_run import NuzlockeRun
|
||||
from app.schemas.run import RunCreate, RunDetailResponse, RunGenlockeContext, RunResponse, RunUpdate
|
||||
from app.schemas.run import (
|
||||
RunCreate,
|
||||
RunDetailResponse,
|
||||
RunGenlockeContext,
|
||||
RunResponse,
|
||||
RunUpdate,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("", response_model=RunResponse, status_code=201)
|
||||
async def create_run(
|
||||
data: RunCreate, session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
async def create_run(data: RunCreate, session: AsyncSession = Depends(get_session)):
|
||||
# Validate game exists
|
||||
game = await session.get(Game, data.game_id)
|
||||
if game is None:
|
||||
@@ -53,12 +57,9 @@ async def get_run(run_id: int, session: AsyncSession = Depends(get_session)):
|
||||
.where(NuzlockeRun.id == run_id)
|
||||
.options(
|
||||
joinedload(NuzlockeRun.game),
|
||||
selectinload(NuzlockeRun.encounters)
|
||||
.joinedload(Encounter.pokemon),
|
||||
selectinload(NuzlockeRun.encounters)
|
||||
.joinedload(Encounter.current_pokemon),
|
||||
selectinload(NuzlockeRun.encounters)
|
||||
.joinedload(Encounter.route),
|
||||
selectinload(NuzlockeRun.encounters).joinedload(Encounter.pokemon),
|
||||
selectinload(NuzlockeRun.encounters).joinedload(Encounter.current_pokemon),
|
||||
selectinload(NuzlockeRun.encounters).joinedload(Encounter.route),
|
||||
)
|
||||
)
|
||||
run = result.scalar_one_or_none()
|
||||
@@ -134,7 +135,10 @@ async def update_run(
|
||||
update_data = data.model_dump(exclude_unset=True)
|
||||
|
||||
# Validate hof_encounter_ids if provided
|
||||
if "hof_encounter_ids" in update_data and update_data["hof_encounter_ids"] is not None:
|
||||
if (
|
||||
"hof_encounter_ids" in update_data
|
||||
and update_data["hof_encounter_ids"] is not None
|
||||
):
|
||||
hof_ids = update_data["hof_encounter_ids"]
|
||||
if len(hof_ids) > 6:
|
||||
raise HTTPException(
|
||||
@@ -156,7 +160,8 @@ async def update_run(
|
||||
detail=f"Encounters not found in this run: {missing}",
|
||||
)
|
||||
not_alive = [
|
||||
eid for eid, e in found.items()
|
||||
eid
|
||||
for eid, e in found.items()
|
||||
if e.status != "caught" or e.faint_level is not None
|
||||
]
|
||||
if not_alive:
|
||||
@@ -168,13 +173,15 @@ async def update_run(
|
||||
# Auto-set completed_at when ending a run
|
||||
if "status" in update_data and update_data["status"] in ("completed", "failed"):
|
||||
if run.status != "active":
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Only active runs can be ended"
|
||||
)
|
||||
update_data["completed_at"] = datetime.now(timezone.utc)
|
||||
raise HTTPException(status_code=400, detail="Only active runs can be ended")
|
||||
update_data["completed_at"] = datetime.now(UTC)
|
||||
|
||||
# Block reactivating a completed/failed run that belongs to a genlocke
|
||||
if "status" in update_data and update_data["status"] == "active" and run.status != "active":
|
||||
if (
|
||||
"status" in update_data
|
||||
and update_data["status"] == "active"
|
||||
and run.status != "active"
|
||||
):
|
||||
leg_result = await session.execute(
|
||||
select(GenlockeLeg).where(GenlockeLeg.run_id == run_id)
|
||||
)
|
||||
@@ -215,9 +222,7 @@ async def update_run(
|
||||
|
||||
|
||||
@router.delete("/{run_id}", status_code=204)
|
||||
async def delete_run(
|
||||
run_id: int, session: AsyncSession = Depends(get_session)
|
||||
):
|
||||
async def delete_run(run_id: int, session: AsyncSession = Depends(get_session)):
|
||||
run = await session.get(NuzlockeRun, run_id)
|
||||
if run is None:
|
||||
raise HTTPException(status_code=404, detail="Run not found")
|
||||
|
||||
Reference in New Issue
Block a user