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,6 @@
|
||||
"""Pydantic schemas package."""
|
||||
|
||||
from app.schemas.contact import ContactCreate, ContactResponse
|
||||
from app.schemas.equipment import EquipmentDetail, EquipmentItem, PaginatedEquipment
|
||||
|
||||
__all__ = ["ContactCreate", "ContactResponse", "EquipmentDetail", "EquipmentItem", "PaginatedEquipment"]
|
||||
@@ -0,0 +1,27 @@
|
||||
"""Pydantic schemas for contact form."""
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, model_validator
|
||||
|
||||
|
||||
class ContactCreate(BaseModel):
|
||||
"""Contact form input schema."""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
email: EmailStr
|
||||
phone: str | None = Field(None, max_length=64)
|
||||
message: str = Field(..., min_length=1, max_length=5000)
|
||||
privacy_consent: bool = Field(..., description="Must be True")
|
||||
|
||||
@model_validator(mode="after")
|
||||
def consent_must_be_true(self) -> "ContactCreate":
|
||||
"""Reject submissions where privacy_consent is not True."""
|
||||
if not self.privacy_consent:
|
||||
raise ValueError("privacy_consent must be True")
|
||||
return self
|
||||
|
||||
|
||||
class ContactResponse(BaseModel):
|
||||
"""Contact form response."""
|
||||
|
||||
success: bool
|
||||
message: str = "Kontakt-Anfrage erfolgreich gesendet."
|
||||
@@ -0,0 +1,50 @@
|
||||
"""Pydantic schemas for equipment endpoints."""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class EquipmentItem(BaseModel):
|
||||
"""Equipment item for list responses."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
rentman_id: str
|
||||
name: str
|
||||
number: str | None = None
|
||||
category: str | None = None
|
||||
description: str | None = None
|
||||
image_url: str | None = None
|
||||
rental_price: Decimal | None = None
|
||||
available: bool = True
|
||||
|
||||
|
||||
class EquipmentDetail(BaseModel):
|
||||
"""Equipment detail with full specifications."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
rentman_id: str
|
||||
name: str
|
||||
number: str | None = None
|
||||
category: str | None = None
|
||||
subcategory: str | None = None
|
||||
description: str | None = None
|
||||
specifications: dict | None = None
|
||||
images: list | None = None
|
||||
rental_price: Decimal | None = None
|
||||
brand: str | None = None
|
||||
available: bool = True
|
||||
|
||||
|
||||
class PaginatedEquipment(BaseModel):
|
||||
"""Paginated response for equipment list."""
|
||||
|
||||
items: list[EquipmentItem]
|
||||
total: int
|
||||
page: int
|
||||
page_size: int
|
||||
total_pages: int
|
||||
Reference in New Issue
Block a user