47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
from fastapi import APIRouter, Depends, Query, HTTPException
|
|
from typing import Optional
|
|
from middleware.auth import require_auth
|
|
from core import copernicus
|
|
|
|
"""
|
|
api.mebboat.it/marine/...
|
|
"""
|
|
|
|
router = APIRouter(prefix="/catalog", tags=["Copernicus Marine Database"])
|
|
|
|
@router.get("")
|
|
async def list_catalog(
|
|
search: Optional[str] = Query(None, description="Cerca per nome o ID"),
|
|
limit: int = Query(50, ge=1, le=200),
|
|
offset: int = Query(0, ge=0),
|
|
user=Depends(require_auth)
|
|
):
|
|
"""
|
|
[API] Ottieni una lista di dataset corrispondeti alla query di ricerca, con paginazione.
|
|
Ogni dataset include ID, titolo, descrizione, variabili, posizione e finestra di tempo.
|
|
I risultati rimangono salvati nella cache del server per un ora.
|
|
"""
|
|
try:
|
|
return copernicus.get_catalog(search=search, limit=limit, offset=offset)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=502, detail=f"Catalog unavailable: {str(e)}")
|
|
|
|
|
|
@router.get("/{dataset_id}")
|
|
async def get_dataset(
|
|
dataset_id: str,
|
|
user=Depends(require_auth)
|
|
):
|
|
"""
|
|
[API] Ottieni i dati di un dataset dal catalogo di Copernics Marine.
|
|
"""
|
|
try:
|
|
info = copernicus.get_dataset_info(dataset_id)
|
|
except Exception as e:
|
|
raise HTTPException(status_code=502, detail=f"Catalog unavailable: {str(e)}")
|
|
|
|
if info is None:
|
|
raise HTTPException(status_code=404, detail=f"Dataset '{dataset_id}' not found in catalog")
|
|
|
|
return info
|