Seed all Pokemon species and add admin pagination
- Update fetch_pokeapi.py to import all 1025 Pokemon species instead of only those appearing in encounters - Add paginated response for /pokemon endpoint with total count - Add pagination controls to AdminPokemon page (First/Prev/Next/Last) - Show current page and total count in admin UI - Add bean for Pokemon forms support task - Update UX improvements bean with route grouping polish item Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from app.schemas.pokemon import (
|
||||
BulkImportItem,
|
||||
BulkImportResult,
|
||||
EvolutionResponse,
|
||||
PaginatedPokemonResponse,
|
||||
PokemonCreate,
|
||||
PokemonResponse,
|
||||
PokemonUpdate,
|
||||
@@ -23,21 +24,35 @@ from app.schemas.pokemon import (
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/pokemon", response_model=list[PokemonResponse])
|
||||
@router.get("/pokemon", response_model=PaginatedPokemonResponse)
|
||||
async def list_pokemon(
|
||||
search: str | None = Query(None),
|
||||
limit: int = Query(50, ge=1, le=500),
|
||||
offset: int = Query(0, ge=0),
|
||||
session: AsyncSession = Depends(get_session),
|
||||
):
|
||||
query = select(Pokemon)
|
||||
# Build base query with optional search filter
|
||||
base_query = select(Pokemon)
|
||||
if search:
|
||||
query = query.where(
|
||||
base_query = base_query.where(
|
||||
func.lower(Pokemon.name).contains(search.lower())
|
||||
)
|
||||
query = query.order_by(Pokemon.national_dex).offset(offset).limit(limit)
|
||||
result = await session.execute(query)
|
||||
return result.scalars().all()
|
||||
|
||||
# Get total count
|
||||
count_query = select(func.count()).select_from(base_query.subquery())
|
||||
total = (await session.execute(count_query)).scalar() or 0
|
||||
|
||||
# Get paginated items
|
||||
items_query = base_query.order_by(Pokemon.national_dex).offset(offset).limit(limit)
|
||||
result = await session.execute(items_query)
|
||||
items = result.scalars().all()
|
||||
|
||||
return PaginatedPokemonResponse(
|
||||
items=items,
|
||||
total=total,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
|
||||
|
||||
@router.post("/pokemon/bulk-import", response_model=BulkImportResult)
|
||||
|
||||
Reference in New Issue
Block a user