- Updated README.md to reflect new features and usage instructions. - Removed deprecated Dashboard.html component and integrated dashboard functionality directly into the main application. - Revised architecture documentation for clarity and added module map and request flow diagrams. - Enhanced maintenance model to include equipment association and cost tracking. - Updated requirements.txt to include new dependencies (httpx, pandas, numpy). - Improved consumption, maintenance, production, and reporting routes with better validation and response handling. - Added unit tests for maintenance and production routes, ensuring proper CRUD operations and validation. - Enhanced reporting service to calculate and return detailed summary statistics. - Redesigned Dashboard.html for improved user experience and integrated Chart.js for visualizing simulation results.
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
from typing import List, Optional
|
|
|
|
from fastapi import APIRouter, Depends, status
|
|
from pydantic import BaseModel, PositiveFloat
|
|
from sqlalchemy.orm import Session
|
|
|
|
from config.database import SessionLocal
|
|
from models.production_output import ProductionOutput
|
|
|
|
|
|
router = APIRouter(prefix="/api/production", tags=["Production"])
|
|
|
|
|
|
def get_db():
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|
|
|
|
|
|
class ProductionOutputBase(BaseModel):
|
|
scenario_id: int
|
|
amount: PositiveFloat
|
|
description: Optional[str] = None
|
|
|
|
|
|
class ProductionOutputCreate(ProductionOutputBase):
|
|
pass
|
|
|
|
|
|
class ProductionOutputRead(ProductionOutputBase):
|
|
id: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
|
|
@router.post("/", response_model=ProductionOutputRead, status_code=status.HTTP_201_CREATED)
|
|
def create_production(item: ProductionOutputCreate, db: Session = Depends(get_db)):
|
|
db_item = ProductionOutput(**item.dict())
|
|
db.add(db_item)
|
|
db.commit()
|
|
db.refresh(db_item)
|
|
return db_item
|
|
|
|
|
|
@router.get("/", response_model=List[ProductionOutputRead])
|
|
def list_production(db: Session = Depends(get_db)):
|
|
return db.query(ProductionOutput).all()
|