22 lines
577 B
Python
22 lines
577 B
Python
from typing import Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.rental import Category
|
|
from app.schemas.category import CategoryCreate, CategoryUpdate
|
|
|
|
|
|
class CRUDCategory(CRUDBase[Category, CategoryCreate, CategoryUpdate]):
|
|
"""
|
|
CRUD operations for Category model.
|
|
"""
|
|
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Category]:
|
|
"""
|
|
Get a category by name.
|
|
"""
|
|
return db.query(Category).filter(Category.name == name).first()
|
|
|
|
|
|
category = CRUDCategory(Category) |