Automated Action 439330125e Fix code linting issues
- Fix unused imports in API endpoints
- Add proper __all__ exports in model and schema modules
- Add proper TYPE_CHECKING imports in models to prevent circular imports
- Fix import order in migrations
- Fix long lines in migration scripts
- All ruff checks passing
2025-06-05 16:58:14 +00:00

44 lines
1.2 KiB
Python

import uuid
from typing import List, Optional
from sqlalchemy.orm import Session
from app.crud.base import CRUDBase
from app.models.category 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()
def create(self, db: Session, *, obj_in: CategoryCreate) -> Category:
"""
Create a new category.
"""
db_obj = Category(
id=str(uuid.uuid4()),
name=obj_in.name,
description=obj_in.description,
)
db.add(db_obj)
db.commit()
db.refresh(db_obj)
return db_obj
def get_multi_by_ids(
self, db: Session, *, ids: List[str], skip: int = 0, limit: int = 100
) -> List[Category]:
"""
Get multiple categories by IDs.
"""
return db.query(Category).filter(Category.id.in_(ids)).offset(skip).limit(limit).all()
category = CRUDCategory(Category)