30 lines
760 B
Python
30 lines
760 B
Python
"""
|
|
Item CRUD module.
|
|
"""
|
|
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.item import Item
|
|
from app.schemas.item import ItemCreate, ItemUpdate
|
|
|
|
|
|
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
|
|
"""
|
|
CRUD for Item.
|
|
"""
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Item]:
|
|
"""
|
|
Get item by name.
|
|
"""
|
|
return db.query(Item).filter(Item.name == name).first()
|
|
|
|
def get_active(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Item]:
|
|
"""
|
|
Get active items.
|
|
"""
|
|
return db.query(Item).filter(Item.is_active == True).offset(skip).limit(limit).all() # noqa
|
|
|
|
|
|
item = CRUDItem(Item) |