
This commit includes: - Project structure setup with FastAPI - Database models with SQLAlchemy (users, products, categories, orders) - SQLite database configuration - Alembic migration scripts - API endpoints for authentication, users, products, categories, and orders - JWT authentication - Comprehensive documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.product import Product, Category
|
|
from app.schemas.product import ProductCreate, ProductUpdate, CategoryCreate, CategoryUpdate
|
|
|
|
|
|
class CRUDProduct(CRUDBase[Product, ProductCreate, ProductUpdate]):
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Product]:
|
|
return db.query(Product).filter(Product.name == name).first()
|
|
|
|
def get_by_category(self, db: Session, *, category_id: int, skip: int = 0, limit: int = 100) -> List[Product]:
|
|
return db.query(Product).filter(Product.category_id == category_id).offset(skip).limit(limit).all()
|
|
|
|
def get_active(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Product]:
|
|
return db.query(Product).filter(Product.is_active == True).offset(skip).limit(limit).all()
|
|
|
|
|
|
product = CRUDProduct(Product)
|
|
|
|
|
|
class CRUDCategory(CRUDBase[Category, CategoryCreate, CategoryUpdate]):
|
|
def get_by_name(self, db: Session, *, name: str) -> Optional[Category]:
|
|
return db.query(Category).filter(Category.name == name).first()
|
|
|
|
|
|
category = CRUDCategory(Category) |