Files
house-elo-ranking/backend/app/routers/images.py
2026-03-06 14:06:45 +00:00

32 lines
845 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Image endpoints retrieve photo URLs from the raw Funda data."""
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy import text
from sqlalchemy.orm import Session
from app.config import settings
from app.database import get_db
router = APIRouter()
@router.get("/listings/{global_id}/images")
def get_listing_images(
global_id: str,
db: Session = Depends(get_db),
) -> dict[str, list[str]]:
"""Return image URLs for a listing from the raw Funda JSON data."""
row = db.execute(
text(
"SELECT raw_json->'photo_urls' AS photo_urls "
"FROM raw_funda.listing_details "
"WHERE global_id = :gid"
),
{"gid": global_id},
).first()
if not row or not row.photo_urls:
return {"images": []}
return {"images": list(row.photo_urls)}