from typing import List from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from app.api.v1.models.and import And from app.api.v1.schemas.and import AndCreate, AndResponse from app.api.core.dependencies.dependencies import get_db router = APIRouter() @router.get("/ands", response_model=List[AndResponse]) def read_ands(db: Session = Depends(get_db)): ands = db.query(And).all() return ands @router.post("/ands", response_model=AndResponse) def create_and(and_data: AndCreate, db: Session = Depends(get_db)): and_instance = And(**and_data.dict()) db.add(and_instance) db.commit() db.refresh(and_instance) return and_instance @router.get("/ands/{id}", response_model=AndResponse) def read_and(id: int, db: Session = Depends(get_db)): and_instance = db.query(And).get(id) if not and_instance: raise HTTPException(status_code=404, detail="And not found") return and_instance