
- 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
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
import uuid
|
|
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.supplier import Supplier
|
|
from app.schemas.supplier import SupplierCreate, SupplierUpdate
|
|
|
|
|
|
class CRUDSupplier(CRUDBase[Supplier, SupplierCreate, SupplierUpdate]):
|
|
"""
|
|
CRUD operations for Supplier model.
|
|
"""
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Supplier]:
|
|
"""
|
|
Get a supplier by name.
|
|
"""
|
|
return db.query(Supplier).filter(Supplier.name == name).first()
|
|
|
|
def create(self, db: Session, *, obj_in: SupplierCreate) -> Supplier:
|
|
"""
|
|
Create a new supplier.
|
|
"""
|
|
db_obj = Supplier(
|
|
id=str(uuid.uuid4()),
|
|
name=obj_in.name,
|
|
contact_name=obj_in.contact_name,
|
|
email=obj_in.email,
|
|
phone=obj_in.phone,
|
|
address=obj_in.address,
|
|
notes=obj_in.notes,
|
|
)
|
|
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[Supplier]:
|
|
"""
|
|
Get multiple suppliers by IDs.
|
|
"""
|
|
return db.query(Supplier).filter(Supplier.id.in_(ids)).offset(skip).limit(limit).all()
|
|
|
|
|
|
supplier = CRUDSupplier(Supplier) |