Public PPR submission

This commit is contained in:
James Pattinson
2025-10-25 12:59:07 +00:00
parent b6e32eccad
commit 91e820b9a8
4 changed files with 672 additions and 1 deletions

View File

@@ -68,4 +68,39 @@ async def search_airports(
(Airport.city.ilike("%" + search_term + "%"))
).limit(limit).all()
return airports
return airports
@router.get("/public/lookup/{code_or_name}", response_model=List[AirportSchema])
async def public_lookup_airport_by_code_or_name(
code_or_name: str,
db: Session = Depends(get_db)
):
"""
Public lookup airport by ICAO code or name.
If input is 4 characters and all uppercase letters, treat as ICAO code.
Otherwise, search by name.
No authentication required.
"""
clean_input = code_or_name.strip().upper()
if len(clean_input) < 2:
return []
# Check if input looks like an ICAO code (4 letters)
if len(clean_input) == 4 and clean_input.isalpha():
# Exact ICAO match first
airport = db.query(Airport).filter(Airport.icao == clean_input).first()
if airport:
return [airport]
# Then search ICAO codes that start with input
airports = db.query(Airport).filter(
Airport.icao.like(clean_input + "%")
).limit(5).all()
return airports
else:
# Search by name (case-insensitive partial match)
airports = db.query(Airport).filter(
Airport.name.ilike("%" + code_or_name + "%")
).limit(10).all()
return airports