feat: T03 backend core – FastAPI + DB models + Equipment API + Redis cache + health + tests
- FastAPI app with CORS, lifespan handlers - Pydantic Settings config (DB, Redis, CORS, SMTP, JWT, Rentman) - SQLAlchemy async engine + session (DeclarativeBase) - 6 DB models: EquipmentCache, RentalRequest, RentalRequestItem, Contact, AdminUser, SyncLog - Pydantic schemas: EquipmentItem, EquipmentDetail, PaginatedEquipment, ContactCreate, ContactResponse - Redis cache helper: set/get/delete_pattern, rate limiting, equipment key builders - Equipment router: list (search/category/sort/pagination), detail, categories – all cached - Contact router: POST with Pydantic validation + rate limiting (5/min) - Health router: GET /api/health with DB + Redis status - 28 pytest tests (all pass, 90% coverage) - Dockerfile, requirements.txt, pytest.ini, test_report.md
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""RentalRequest and RentalRequestItem SQLAlchemy models."""
|
||||
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import Date, ForeignKey, Index, Integer, Numeric, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class RentalRequest(Base):
|
||||
"""Rental request submitted by a customer."""
|
||||
|
||||
__tablename__ = "rental_requests"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
reference_number: Mapped[str] = mapped_column(String(32), unique=True, nullable=False)
|
||||
event_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
date_start: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
date_end: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
location: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
person_count: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
contact_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
contact_company: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
contact_email: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
contact_phone: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
contact_street: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
contact_postalcode: Mapped[str | None] = mapped_column(String(16), nullable=True)
|
||||
contact_city: Mapped[str | None] = mapped_column(String(128), nullable=True)
|
||||
message: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False)
|
||||
rentman_request_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
rentman_sync_status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False)
|
||||
rentman_sync_error: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(server_default=func.now(), nullable=False)
|
||||
|
||||
items: Mapped[list["RentalRequestItem"]] = relationship(back_populates="rental_request", cascade="all, delete-orphan")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_rental_status", "status"),
|
||||
)
|
||||
|
||||
|
||||
class RentalRequestItem(Base):
|
||||
"""Individual equipment line item in a rental request."""
|
||||
|
||||
__tablename__ = "rental_request_items"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
rental_request_id: Mapped[int] = mapped_column(ForeignKey("rental_requests.id", ondelete="CASCADE"), nullable=False)
|
||||
equipment_id: Mapped[int | None] = mapped_column(ForeignKey("equipment_cache.id"), nullable=True)
|
||||
equipment_name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||
rentman_equipment_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
|
||||
quantity: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
|
||||
unit_price: Mapped[float | None] = mapped_column(Numeric(10, 2), nullable=True)
|
||||
rentman_sync_status: Mapped[str] = mapped_column(String(32), default="pending", nullable=False)
|
||||
|
||||
rental_request: Mapped["RentalRequest"] = relationship(back_populates="items")
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_rental_items_request", "rental_request_id"),
|
||||
)
|
||||
Reference in New Issue
Block a user