19 lines
611 B
Python
19 lines
611 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from .. import models, schemas, database
|
|
|
|
auditories = APIRouter(prefix="/auditories", tags=["auditories"])
|
|
|
|
@auditories.post("/", response_model=schemas.AuditoryRead)
|
|
def create_auditory(item: schemas.AuditoryCreate, db: Session = Depends(database.get_db)):
|
|
obj = models.Auditory(**item.dict())
|
|
db.add(obj)
|
|
db.commit()
|
|
db.refresh(obj)
|
|
return obj
|
|
|
|
@auditories.get("/", response_model=list[schemas.AuditoryRead])
|
|
def list_auditories(db: Session = Depends(database.get_db)):
|
|
return db.query(models.Auditory).all()
|
|
|