57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
from ..schemas import (
|
|
ICSRequest,
|
|
AbfallIORequest,
|
|
AWMRequest,
|
|
StuttgartRequest,
|
|
CollectionsResponse,
|
|
)
|
|
from ..collector import fetch_ics, fetch_abfall_io, fetch_awm_muenchen, fetch_stuttgart
|
|
|
|
router = APIRouter(prefix="/collections", tags=["collections"])
|
|
|
|
|
|
@router.post("/ics", response_model=CollectionsResponse)
|
|
def collections_ics(body: ICSRequest):
|
|
try:
|
|
collections = fetch_ics(body.url, body.count)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|
|
if not collections:
|
|
raise HTTPException(status_code=422, detail="No collections returned from this ICS URL")
|
|
return CollectionsResponse(source="ics", collections=collections)
|
|
|
|
|
|
@router.post("/abfall_io", response_model=CollectionsResponse)
|
|
def collections_abfall_io(body: AbfallIORequest):
|
|
try:
|
|
collections = fetch_abfall_io(body.key, body.f_id_kommune, body.f_id_strasse, body.count)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|
|
if not collections:
|
|
raise HTTPException(status_code=422, detail="No collections returned. Check your IDs.")
|
|
return CollectionsResponse(source="abfall_io", collections=collections)
|
|
|
|
|
|
@router.post("/awm_muenchen_de", response_model=CollectionsResponse)
|
|
def collections_awm_muenchen(body: AWMRequest):
|
|
try:
|
|
collections = fetch_awm_muenchen(body.street, body.house_number, body.count)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|
|
if not collections:
|
|
raise HTTPException(status_code=422, detail="No collections returned. Check street name.")
|
|
return CollectionsResponse(source="awm_muenchen_de", collections=collections)
|
|
|
|
|
|
@router.post("/stuttgart_de", response_model=CollectionsResponse)
|
|
def collections_stuttgart(body: StuttgartRequest):
|
|
try:
|
|
collections = fetch_stuttgart(body.street, body.streetnr, body.count)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=422, detail=str(e))
|
|
if not collections:
|
|
raise HTTPException(status_code=422, detail="No collections returned. Check street name and number.")
|
|
return CollectionsResponse(source="stuttgart_de", collections=collections)
|