Add name suggestion engine with API endpoint and tests
Expand services/naming.py with suggest_names() that picks random words
from a category while excluding nicknames already used in the run. Add
GET /runs/{run_id}/name-suggestions?count=10 endpoint that reads the
run's naming_scheme and returns filtered suggestions. Includes 12 unit
tests covering selection, exclusion, exhaustion, and cross-category
independence.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ from app.schemas.run import (
|
||||
RunResponse,
|
||||
RunUpdate,
|
||||
)
|
||||
from app.services.naming import get_naming_categories
|
||||
from app.services.naming import get_naming_categories, suggest_names
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -29,6 +29,31 @@ async def list_naming_categories():
|
||||
return get_naming_categories()
|
||||
|
||||
|
||||
@router.get("/{run_id}/name-suggestions", response_model=list[str])
|
||||
async def get_name_suggestions(
|
||||
run_id: int,
|
||||
count: int = 10,
|
||||
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")
|
||||
|
||||
if not run.naming_scheme:
|
||||
return []
|
||||
|
||||
# Collect nicknames already used in this run
|
||||
result = await session.execute(
|
||||
select(Encounter.nickname).where(
|
||||
Encounter.run_id == run_id,
|
||||
Encounter.nickname.isnot(None),
|
||||
)
|
||||
)
|
||||
used_names = {row[0] for row in result}
|
||||
|
||||
return suggest_names(run.naming_scheme, used_names, count)
|
||||
|
||||
|
||||
@router.post("", response_model=RunResponse, status_code=201)
|
||||
async def create_run(data: RunCreate, session: AsyncSession = Depends(get_session)):
|
||||
# Validate game exists
|
||||
|
||||
Reference in New Issue
Block a user