2025-03-20 14:07:41 +01:00

29 lines
923 B
Python

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_create: AndCreate, db: Session = Depends(get_db)):
and_db = And(**and_create.dict())
db.add(and_db)
db.commit()
db.refresh(and_db)
return and_db
@router.get("/ands/{id}", response_model=AndResponse)
def read_and(id: int, db: Session = Depends(get_db)):
and_db = db.query(And).get(id)
if not and_db:
raise HTTPException(status_code=404, detail="And not found")
return and_db