35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from typing import Annotated
|
|
from api.auth import get_current_user
|
|
from api.config import DEV_TIER_ORIGINS, PROD_TIER_ORIGINS
|
|
from fastapi import Depends, FastAPI
|
|
from api.auth import User
|
|
from repositories.listing_repository import ListingRepository
|
|
from repositories.listing_repository import ListingRepository
|
|
from database import engine
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from ui_exporter import export_immoweb
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
# Allow CORS (for React frontend)
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=[*DEV_TIER_ORIGINS, *PROD_TIER_ORIGINS],
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
|
|
@app.get("/api/listing")
|
|
async def get_listing(user: Annotated[User, Depends(get_current_user)]):
|
|
repository = ListingRepository(engine)
|
|
listings = await repository.get_listings(limit=5)
|
|
return {"listings": listings}
|
|
|
|
|
|
@app.get("/api/listing_geojson")
|
|
async def get_listing_geojson(user: Annotated[User, Depends(get_current_user)]):
|
|
repository = ListingRepository(engine)
|
|
geojson_data = await export_immoweb(repository, limit=None)
|
|
return geojson_data
|