mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Persist window and door ventilation via SQLModel tables 🟥
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0211fb8092
commit
192a3cf20f
2 changed files with 75 additions and 4 deletions
|
|
@ -4,7 +4,15 @@ from typing import ClassVar, Optional
|
|||
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
from datatypes.magicplan.domain.models import Door, Floor, Plan, Room, Window
|
||||
from datatypes.magicplan.domain.models import (
|
||||
Door,
|
||||
DoorVentilation,
|
||||
Floor,
|
||||
Plan,
|
||||
Room,
|
||||
Window,
|
||||
WindowVentilation,
|
||||
)
|
||||
|
||||
|
||||
class MagicPlanPlanModel(SQLModel, table=True):
|
||||
|
|
@ -93,3 +101,29 @@ class MagicPlanDoorModel(SQLModel, table=True):
|
|||
@classmethod
|
||||
def from_domain(cls, door: Door, room_id: int) -> "MagicPlanDoorModel":
|
||||
return cls(magic_plan_room_id=room_id, width_mm=door.width_mm)
|
||||
|
||||
|
||||
class MagicPlanWindowVentilationModel(SQLModel, table=True):
|
||||
__tablename__: ClassVar[str] = "magic_plan_window_ventilation" # pyright: ignore[reportIncompatibleVariableOverride]
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
magic_plan_window_id: int = Field(foreign_key="magic_plan_window.id")
|
||||
|
||||
@classmethod
|
||||
def from_domain(
|
||||
cls, _ventilation: WindowVentilation, _window_id: int
|
||||
) -> "MagicPlanWindowVentilationModel":
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class MagicPlanDoorVentilationModel(SQLModel, table=True):
|
||||
__tablename__: ClassVar[str] = "magic_plan_door_ventilation" # pyright: ignore[reportIncompatibleVariableOverride]
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
magic_plan_door_id: int = Field(foreign_key="magic_plan_door.id")
|
||||
|
||||
@classmethod
|
||||
def from_domain(
|
||||
cls, _ventilation: DoorVentilation, _door_id: int
|
||||
) -> "MagicPlanDoorVentilationModel":
|
||||
raise NotImplementedError
|
||||
|
|
|
|||
|
|
@ -3,13 +3,23 @@ from __future__ import annotations
|
|||
from sqlalchemy import Engine
|
||||
from sqlmodel import Session, select
|
||||
|
||||
from datatypes.magicplan.domain.models import Door, Floor, Plan, Room, Window
|
||||
from datatypes.magicplan.domain.models import (
|
||||
Door,
|
||||
DoorVentilation,
|
||||
Floor,
|
||||
Plan,
|
||||
Room,
|
||||
Window,
|
||||
WindowVentilation,
|
||||
)
|
||||
from infrastructure.postgres.magic_plan_tables import (
|
||||
MagicPlanDoorModel,
|
||||
MagicPlanDoorVentilationModel,
|
||||
MagicPlanFloorModel,
|
||||
MagicPlanPlanModel,
|
||||
MagicPlanRoomModel,
|
||||
MagicPlanWindowModel,
|
||||
MagicPlanWindowVentilationModel,
|
||||
)
|
||||
from repositories.magic_plan.magic_plan_postgres_repository import (
|
||||
MagicPlanPostgresRepository,
|
||||
|
|
@ -17,8 +27,20 @@ from repositories.magic_plan.magic_plan_postgres_repository import (
|
|||
|
||||
|
||||
def _plan() -> Plan:
|
||||
window = Window(width_m=1.2, height_m=1.5, area_m2=1.8, opening_type="casement")
|
||||
door = Door(width_mm=762.0)
|
||||
window = Window(
|
||||
width_m=1.2,
|
||||
height_m=1.5,
|
||||
area_m2=1.8,
|
||||
opening_type="casement",
|
||||
ventilation=WindowVentilation(
|
||||
opening_type="30.Hinged.Pivot.Window",
|
||||
num_openings=2,
|
||||
pct_openable=70,
|
||||
trickle_vent_area_mm2=1700,
|
||||
num_trickle_vents=2,
|
||||
),
|
||||
)
|
||||
door = Door(width_mm=762.0, ventilation=DoorVentilation(undercut_mm=70.0))
|
||||
room = Room(
|
||||
name="Living Room",
|
||||
width_m=4.0,
|
||||
|
|
@ -55,6 +77,21 @@ def test_save_writes_all_rows(db_engine: Engine) -> None:
|
|||
assert len(session.exec(select(MagicPlanDoorModel)).all()) == 1
|
||||
|
||||
|
||||
def test_save_writes_ventilation_rows(db_engine: Engine) -> None:
|
||||
# Arrange — plan with one window (with ventilation) and one door (with ventilation)
|
||||
plan = _plan()
|
||||
|
||||
# Act
|
||||
with Session(db_engine) as session:
|
||||
MagicPlanPostgresRepository(session).save(plan, uploaded_file_id=1)
|
||||
session.commit()
|
||||
|
||||
# Assert
|
||||
with Session(db_engine) as session:
|
||||
assert len(session.exec(select(MagicPlanWindowVentilationModel)).all()) == 1
|
||||
assert len(session.exec(select(MagicPlanDoorVentilationModel)).all()) == 1
|
||||
|
||||
|
||||
def test_save_is_idempotent(db_engine: Engine) -> None:
|
||||
# Arrange
|
||||
plan = _plan()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue