feat(11-03): add site_id and site_name to DeviceResponse

- Add site_id (Optional[UUID]) and site_name (Optional[str]) to backend DeviceResponse schema
- Include site fields in _build_device_response helper
- Add selectinload(Device.site) to _device_with_relations for eager loading
- Add site_id and site_name to frontend DeviceResponse interface

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-18 21:50:57 -05:00
parent 6ccccb3902
commit ddb2b3e43a
3 changed files with 9 additions and 0 deletions

View File

@@ -88,6 +88,8 @@ class DeviceResponse(BaseModel):
tls_mode: str = "auto" tls_mode: str = "auto"
tags: list[DeviceTagRef] = [] tags: list[DeviceTagRef] = []
groups: list[DeviceGroupRef] = [] groups: list[DeviceGroupRef] = []
site_id: Optional[uuid.UUID] = None
site_name: Optional[str] = None
created_at: datetime created_at: datetime
model_config = {"from_attributes": True} model_config = {"from_attributes": True}

View File

@@ -109,15 +109,20 @@ def _build_device_response(device: Device) -> DeviceResponse:
tls_mode=device.tls_mode, tls_mode=device.tls_mode,
tags=tags, tags=tags,
groups=groups, groups=groups,
site_id=device.site_id,
site_name=device.site.name if device.site else None,
created_at=device.created_at, created_at=device.created_at,
) )
def _device_with_relations(): def _device_with_relations():
"""Return a select() for Device with tags and groups eagerly loaded.""" """Return a select() for Device with tags and groups eagerly loaded."""
from app.models.site import Site # noqa: F811
return select(Device).options( return select(Device).options(
selectinload(Device.tag_assignments).selectinload(DeviceTagAssignment.tag), selectinload(Device.tag_assignments).selectinload(DeviceTagAssignment.tag),
selectinload(Device.group_memberships).selectinload(DeviceGroupMembership.group), selectinload(Device.group_memberships).selectinload(DeviceGroupMembership.group),
selectinload(Device.site),
) )

View File

@@ -306,6 +306,8 @@ export interface DeviceResponse {
tls_mode: string tls_mode: string
tags: DeviceTagRef[] tags: DeviceTagRef[]
groups: DeviceGroupRef[] groups: DeviceGroupRef[]
site_id: string | null
site_name: string | null
created_at: string created_at: string
} }