Files
bambuddy/backend/app/models/maintenance.py
T
maziggy 83cbac04b7 - Add interactive API Browser to Settings > API Keys
- New APIBrowser component with full OpenAPI schema integration
    - Fetches and parses /openapi.json automatically
    - Groups endpoints by API tags (printers, archives, settings, etc.)
    - Expandable endpoint sections with color-coded method badges
    - Path parameter, query parameter, and JSON body editors
    - Auto-populates request body with schema examples
    - Live API request execution with response display
    - Response shows status code, timing, and formatted JSON
    - Copy response button with clipboard fallback
    - Search to filter endpoints across all categories
    - Expand All / Collapse All buttons
    - Link to Swagger UI (/docs)

  - Two-column layout for API Keys tab
    - Left: API key management + webhook documentation
    - Right: API Browser with dedicated test key input

  - Parameter validation
    - Shows warning for missing required parameters
    - Validates before sending requests to avoid 422 errors

  - UX improvements
    - "Use in API Browser" button on newly created keys
    - Responsive layout (stacked on mobile, side-by-side on xl+)
2026-01-02 15:00:21 +01:00

79 lines
3.4 KiB
Python

"""Maintenance tracking models."""
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Float, ForeignKey, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from backend.app.core.database import Base
class MaintenanceType(Base):
"""Defines a type of maintenance task with default interval."""
__tablename__ = "maintenance_types"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(100))
description: Mapped[str | None] = mapped_column(Text)
default_interval_hours: Mapped[float] = mapped_column(Float, default=100.0)
# Interval type: "hours" (print hours) or "days" (calendar days)
interval_type: Mapped[str] = mapped_column(String(20), default="hours")
icon: Mapped[str | None] = mapped_column(String(50)) # Icon name for UI
is_system: Mapped[bool] = mapped_column(Boolean, default=False) # Pre-defined vs custom
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
# Relationships
printer_maintenance: Mapped[list["PrinterMaintenance"]] = relationship(
back_populates="maintenance_type", cascade="all, delete-orphan"
)
class PrinterMaintenance(Base):
"""Tracks maintenance status for a specific printer."""
__tablename__ = "printer_maintenance"
id: Mapped[int] = mapped_column(primary_key=True)
printer_id: Mapped[int] = mapped_column(ForeignKey("printers.id", ondelete="CASCADE"))
maintenance_type_id: Mapped[int] = mapped_column(ForeignKey("maintenance_types.id", ondelete="CASCADE"))
# Custom interval for this printer (overrides default if set)
custom_interval_hours: Mapped[float | None] = mapped_column(Float, nullable=True)
# Custom interval type for this printer (overrides default if set)
custom_interval_type: Mapped[str | None] = mapped_column(String(20), nullable=True)
# Tracking
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
last_performed_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
last_performed_hours: Mapped[float] = mapped_column(Float, default=0.0) # Hours at last reset
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now(), onupdate=func.now())
# Relationships
printer: Mapped["Printer"] = relationship(back_populates="maintenance_items")
maintenance_type: Mapped["MaintenanceType"] = relationship(back_populates="printer_maintenance")
history: Mapped[list["MaintenanceHistory"]] = relationship(
back_populates="printer_maintenance", cascade="all, delete-orphan"
)
class MaintenanceHistory(Base):
"""Log of maintenance actions performed."""
__tablename__ = "maintenance_history"
id: Mapped[int] = mapped_column(primary_key=True)
printer_maintenance_id: Mapped[int] = mapped_column(ForeignKey("printer_maintenance.id", ondelete="CASCADE"))
performed_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
hours_at_maintenance: Mapped[float] = mapped_column(Float, default=0.0)
notes: Mapped[str | None] = mapped_column(Text, nullable=True)
# Relationships
printer_maintenance: Mapped["PrinterMaintenance"] = relationship(back_populates="history")
# Import at end to avoid circular imports
from backend.app.models.printer import Printer # noqa: E402