
- 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>
79 lines
2.4 KiB
Python
79 lines
2.4 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 stock_transaction as stock_transaction_crud
|
|
from app.db.session import get_db
|
|
from app.models import User
|
|
from app.models.stock_transaction import TransactionType
|
|
from app.schemas.stock_transaction import StockTransaction, StockTransactionCreate
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", response_model=List[StockTransaction])
|
|
def read_stock_transactions(
|
|
db: Session = Depends(get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
transactions = stock_transaction_crud.get_multi(db, skip=skip, limit=limit)
|
|
return transactions
|
|
|
|
|
|
@router.get("/item/{item_id}", response_model=List[StockTransaction])
|
|
def read_item_transactions(
|
|
*,
|
|
db: Session = Depends(get_db),
|
|
item_id: int,
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
transactions = stock_transaction_crud.get_by_item(
|
|
db, item_id=item_id, skip=skip, limit=limit
|
|
)
|
|
return transactions
|
|
|
|
|
|
@router.get("/type/{transaction_type}", response_model=List[StockTransaction])
|
|
def read_transactions_by_type(
|
|
*,
|
|
db: Session = Depends(get_db),
|
|
transaction_type: TransactionType,
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
transactions = stock_transaction_crud.get_by_type(
|
|
db, transaction_type=transaction_type, skip=skip, limit=limit
|
|
)
|
|
return transactions
|
|
|
|
|
|
@router.post("/", response_model=StockTransaction)
|
|
def create_stock_transaction(
|
|
*,
|
|
db: Session = Depends(get_db),
|
|
transaction_in: StockTransactionCreate,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
transaction = stock_transaction_crud.create_with_stock_update(
|
|
db, obj_in=transaction_in
|
|
)
|
|
return transaction
|
|
|
|
|
|
@router.get("/{id}", response_model=StockTransaction)
|
|
def read_stock_transaction(
|
|
*,
|
|
db: Session = Depends(get_db),
|
|
id: int,
|
|
current_user: User = Depends(get_current_active_user),
|
|
) -> Any:
|
|
transaction = stock_transaction_crud.get(db, id=id)
|
|
if not transaction:
|
|
raise HTTPException(status_code=404, detail="Stock transaction not found")
|
|
return transaction
|