Automated Action 252ce19872 Implement complete small business inventory management system
Features include:
- User management with JWT authentication and role-based access
- Inventory items with SKU/barcode tracking and stock management
- Categories and suppliers organization
- Inventory transactions with automatic stock updates
- Low stock alerts and advanced search/filtering
- RESTful API with comprehensive CRUD operations
- SQLite database with Alembic migrations
- Auto-generated API documentation

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-21 16:10:33 +00:00

38 lines
1.3 KiB
Python

from typing import Optional
from sqlalchemy.orm import Session
from app.crud.base import CRUDBase
from app.models.user import User
from app.schemas.user import UserCreate, UserUpdate
from app.auth.auth_handler import get_password_hash, verify_password
class CRUDUser(CRUDBase[User, UserCreate, UserUpdate]):
def get_by_email(self, db: Session, *, email: str) -> Optional[User]:
return db.query(User).filter(User.email == email).first()
def create(self, db: Session, *, obj_in: UserCreate) -> User:
db_obj = User(
email=obj_in.email,
hashed_password=get_password_hash(obj_in.password),
full_name=obj_in.full_name,
is_active=obj_in.is_active,
)
db.add(db_obj)
db.commit()
db.refresh(db_obj)
return db_obj
def authenticate(self, db: Session, *, email: str, password: str) -> Optional[User]:
user = self.get_by_email(db, email=email)
if not user:
return None
if not verify_password(password, user.hashed_password):
return None
return user
def is_active(self, user: User) -> bool:
return user.is_active
def is_admin(self, user: User) -> bool:
return user.is_admin
user = CRUDUser(User)