fastapi-boilerplate/app/crud/item.py

41 lines
1.3 KiB
Python
Raw Normal View History

2023-08-10 22:46:36 +02:00
from fastapi import HTTPException
from sqlalchemy.orm import Session
from models import Item
from schemas.schemas import ItemCreate, ItemUpdate
from crud.base import CRUDBase
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
pass
# def get_item(self, db: Session, item_id: int):
# item = db.query(Item).filter(Item.id == item_id).first()
# if not item:
# raise HTTPException(status_code=404, detail="Item not found")
# return item
# def get_items(self, db: Session, skip: int = 0, limit: int = 100):
# return db.query(Item).offset(skip).limit(limit).all()
# def create_item(self, db: Session, item: ItemCreate):
# db_item = Item(title=item.title, description=item.description)
# db.add(db_item)
# db.commit()
# db.refresh(db_item)
# return db_item
# def update_item(self, db: Session, item: ItemUpdate):
# db_item = Item(title=item.title, description=item.description)
# db.add(db_item)
# db.commit()
# db.refresh(db_item)
# return db_item
# def delete_item(self, db: Session, item_id: int):
# db.query(Item).filter(Item.id == item_id).first().delete()
# db.commit()
# return
item = CRUDItem(Item)