Spaces:
Running
Running
from fastapi import APIRouter, HTTPException, Depends | |
from sqlalchemy.orm import Session | |
from typing import List | |
from .. import crud, database, schemas | |
router = APIRouter() | |
def get_db(): | |
db = database.SessionLocal() | |
try: | |
yield db | |
finally: | |
db.close() | |
def update_metadata( | |
caption_id: str, | |
update: schemas.CaptionUpdate, | |
db: Session = Depends(get_db) | |
): | |
caption = crud.update_caption(db, caption_id, update) | |
if not caption: | |
raise HTTPException(404, "caption not found") | |
return schemas.CaptionOut.from_orm(caption) | |
def get_sources(db: Session = Depends(get_db)): | |
"""Get all sources for lookup""" | |
return crud.get_sources(db) | |
def get_regions(db: Session = Depends(get_db)): | |
"""Get all regions for lookup""" | |
return crud.get_regions(db) | |
def get_types(db: Session = Depends(get_db)): | |
"""Get all types for lookup""" | |
return crud.get_types(db) | |
def get_spatial_references(db: Session = Depends(get_db)): | |
"""Get all spatial references for lookup""" | |
return crud.get_spatial_references(db) | |
def get_image_types(db: Session = Depends(get_db)): | |
"""Get all image types for lookup""" | |
return crud.get_image_types(db) | |
def get_countries(db: Session = Depends(get_db)): | |
"""Get all countries for lookup""" | |
return crud.get_countries(db) | |