Automated Action e8172f2bc2 Implement complete FastAPI inventory management system
- 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>
2025-06-18 10:55:22 +00:00

54 lines
1.6 KiB
Python

from fastapi import Depends, HTTPException, status
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from jose import JWTError, jwt
from sqlalchemy.orm import Session
from app.core.config import settings
from app.crud import user as user_crud
from app.db.session import get_db
from app.models.user import User
security = HTTPBearer()
def get_current_user(
db: Session = Depends(get_db),
credentials: HTTPAuthorizationCredentials = Depends(security),
) -> User:
credentials_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Could not validate credentials",
headers={"WWW-Authenticate": "Bearer"},
)
try:
payload = jwt.decode(
credentials.credentials,
settings.SECRET_KEY,
algorithms=[settings.ALGORITHM],
)
email: str = payload.get("sub")
if email is None:
raise credentials_exception
except JWTError:
raise credentials_exception
user = user_crud.get_by_email(db, email=email)
if user is None:
raise credentials_exception
return user
def get_current_active_user(current_user: User = Depends(get_current_user)) -> User:
if not user_crud.is_active(current_user):
raise HTTPException(status_code=400, detail="Inactive user")
return current_user
def get_current_active_superuser(
current_user: User = Depends(get_current_user),
) -> User:
if not user_crud.is_superuser(current_user):
raise HTTPException(
status_code=400, detail="The user doesn't have enough privileges"
)
return current_user