Automated Action be0ae5f3b3 Implement small business inventory management system
- Create project structure with FastAPI and SQLAlchemy
- Implement database models for items, categories, suppliers, and stock movements
- Add CRUD operations for all models
- Configure Alembic for database migrations
- Create RESTful API endpoints for inventory management
- Add health endpoint for system monitoring
- Update README with setup and usage instructions

generated with BackendIM... (backend.im)
2025-05-12 16:23:23 +00:00

39 lines
1.6 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, status, Query
from sqlalchemy.orm import Session
from typing import List, Optional
from app.database import get_db
from app.schemas.category import CategoryCreate, CategoryUpdate, CategoryResponse
from app.crud import category as category_crud
router = APIRouter(
prefix="/categories",
tags=["Categories"]
)
@router.get("/", response_model=List[CategoryResponse])
def get_categories(
skip: int = 0,
limit: int = 100,
include_inactive: bool = False,
db: Session = Depends(get_db)
):
return category_crud.get_categories(db, skip=skip, limit=limit, include_inactive=include_inactive)
@router.get("/{category_id}", response_model=CategoryResponse)
def get_category(category_id: int, db: Session = Depends(get_db)):
db_category = category_crud.get_category(db, category_id=category_id)
if db_category is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Category not found")
return db_category
@router.post("/", response_model=CategoryResponse, status_code=status.HTTP_201_CREATED)
def create_category(category: CategoryCreate, db: Session = Depends(get_db)):
return category_crud.create_category(db=db, category=category)
@router.put("/{category_id}", response_model=CategoryResponse)
def update_category(category_id: int, category: CategoryUpdate, db: Session = Depends(get_db)):
return category_crud.update_category(db=db, category_id=category_id, category=category)
@router.delete("/{category_id}")
def delete_category(category_id: int, db: Session = Depends(get_db)):
return category_crud.delete_category(db=db, category_id=category_id)