
- Set up project structure with FastAPI and SQLite - Created database models for users, categories, suppliers, items, and stock transactions - Implemented Alembic for database migrations with proper absolute paths - Built comprehensive CRUD operations for all entities - Added JWT-based authentication and authorization system - Created RESTful API endpoints for all inventory operations - Implemented search, filtering, and low stock alerts - Added health check endpoint and base URL response - Configured CORS for all origins - Set up Ruff for code linting and formatting - Updated README with comprehensive documentation and usage examples The system provides complete inventory management functionality for small businesses including product tracking, supplier management, stock transactions, and reporting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from typing import Any, Dict, Optional, Union
|
|
from sqlalchemy.orm import Session
|
|
from app.core.security import get_password_hash, verify_password
|
|
from app.crud.base import CRUDBase
|
|
from app.models.user import User
|
|
from app.schemas.user import UserCreate, UserUpdate
|
|
|
|
|
|
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 update(
|
|
self, db: Session, *, db_obj: User, obj_in: Union[UserUpdate, Dict[str, Any]]
|
|
) -> User:
|
|
if isinstance(obj_in, dict):
|
|
update_data = obj_in
|
|
else:
|
|
update_data = obj_in.model_dump(exclude_unset=True)
|
|
if "password" in update_data:
|
|
hashed_password = get_password_hash(update_data["password"])
|
|
del update_data["password"]
|
|
update_data["hashed_password"] = hashed_password
|
|
return super().update(db, db_obj=db_obj, obj_in=update_data)
|
|
|
|
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_superuser(self, user: User) -> bool:
|
|
return user.is_superuser
|
|
|
|
|
|
user = CRUDUser(User)
|