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

81 lines
2.3 KiB
Python

from typing import Any, List
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.core.auth import get_current_active_user
from app.crud import supplier as supplier_crud
from app.db.session import get_db
from app.models import User
from app.schemas.supplier import Supplier, SupplierCreate, SupplierUpdate
router = APIRouter()
@router.get("/", response_model=List[Supplier])
def read_suppliers(
db: Session = Depends(get_db),
skip: int = 0,
limit: int = 100,
current_user: User = Depends(get_current_active_user),
) -> Any:
suppliers = supplier_crud.get_multi(db, skip=skip, limit=limit)
return suppliers
@router.post("/", response_model=Supplier)
def create_supplier(
*,
db: Session = Depends(get_db),
supplier_in: SupplierCreate,
current_user: User = Depends(get_current_active_user),
) -> Any:
supplier = supplier_crud.get_by_name(db, name=supplier_in.name)
if supplier:
raise HTTPException(
status_code=400,
detail="Supplier with this name already exists.",
)
supplier = supplier_crud.create(db, obj_in=supplier_in)
return supplier
@router.put("/{id}", response_model=Supplier)
def update_supplier(
*,
db: Session = Depends(get_db),
id: int,
supplier_in: SupplierUpdate,
current_user: User = Depends(get_current_active_user),
) -> Any:
supplier = supplier_crud.get(db, id=id)
if not supplier:
raise HTTPException(status_code=404, detail="Supplier not found")
supplier = supplier_crud.update(db, db_obj=supplier, obj_in=supplier_in)
return supplier
@router.get("/{id}", response_model=Supplier)
def read_supplier(
*,
db: Session = Depends(get_db),
id: int,
current_user: User = Depends(get_current_active_user),
) -> Any:
supplier = supplier_crud.get(db, id=id)
if not supplier:
raise HTTPException(status_code=404, detail="Supplier not found")
return supplier
@router.delete("/{id}", response_model=Supplier)
def delete_supplier(
*,
db: Session = Depends(get_db),
id: int,
current_user: User = Depends(get_current_active_user),
) -> Any:
supplier = supplier_crud.get(db, id=id)
if not supplier:
raise HTTPException(status_code=404, detail="Supplier not found")
supplier = supplier_crud.remove(db, id=id)
return supplier