18 lines
628 B
Python
18 lines
628 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from .. import models, schemas, database
|
|
|
|
consumables = APIRouter(prefix="/consumables", tags=["consumables"])
|
|
|
|
@consumables.post("/", response_model=schemas.ConsumableRead)
|
|
def create_consumable(item: schemas.ConsumableCreate, db: Session = Depends(database.get_db)):
|
|
obj = models.Consumable(**item.dict())
|
|
db.add(obj)
|
|
db.commit()
|
|
db.refresh(obj)
|
|
return obj
|
|
|
|
@consumables.get("/", response_model=list[schemas.ConsumableRead])
|
|
def list_consumables(db: Session = Depends(database.get_db)):
|
|
return db.query(models.Consumable).all()
|