from typing import Any, List from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from app.core.deps import get_db from app.models.cryptocurrency import Cryptocurrency from app.schemas.cryptocurrency import Cryptocurrency as CryptocurrencySchema router = APIRouter() @router.get("/", response_model=List[CryptocurrencySchema]) def read_cryptocurrencies( skip: int = 0, limit: int = 100, db: Session = Depends(get_db), ) -> Any: cryptocurrencies = db.query(Cryptocurrency).filter( Cryptocurrency.is_active ).offset(skip).limit(limit).all() return cryptocurrencies @router.get("/{cryptocurrency_id}", response_model=CryptocurrencySchema) def read_cryptocurrency( cryptocurrency_id: int, db: Session = Depends(get_db), ) -> Any: cryptocurrency = db.query(Cryptocurrency).filter( Cryptocurrency.id == cryptocurrency_id ).first() if not cryptocurrency: raise HTTPException(status_code=404, detail="Cryptocurrency not found") return cryptocurrency