From 7a062aad0e2a6c2225eeac17d532efaa16a865f9 Mon Sep 17 00:00:00 2001
From: Daniel K Lyons <dlyons@nrao.edu>
Date: Wed, 11 Sep 2024 15:34:54 -0600
Subject: [PATCH] Facility Configurations on Facility in a dict

---
 .../domain_layer/entities/src/available_time_model.py     | 4 +++-
 .../solicit/domain_layer/entities/src/capability.py       | 8 +++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/middle_layer/allocate/domain_layer/entities/src/available_time_model.py b/middle_layer/allocate/domain_layer/entities/src/available_time_model.py
index 1a4386efd..57b5706f4 100644
--- a/middle_layer/allocate/domain_layer/entities/src/available_time_model.py
+++ b/middle_layer/allocate/domain_layer/entities/src/available_time_model.py
@@ -77,7 +77,9 @@ class AvailableTimeModel(Base, FacilityConfigurationSupport):
     start_date: datetime = Column("start_date", DateTime(timezone=True))
     end_date: datetime = Column("end_date", DateTime(timezone=True))
     facility_configurations: list[FacilityConfiguration] = relationship(
-        FacilityConfiguration, secondary="available_time_model_facility_configurations"
+        FacilityConfiguration,
+        secondary="available_time_model_facility_configurations",
+        order_by=FacilityConfiguration.display_order,
     )
 
     def __init__(
diff --git a/middle_layer/solicit/domain_layer/entities/src/capability.py b/middle_layer/solicit/domain_layer/entities/src/capability.py
index c3341eba9..1b083f986 100644
--- a/middle_layer/solicit/domain_layer/entities/src/capability.py
+++ b/middle_layer/solicit/domain_layer/entities/src/capability.py
@@ -42,7 +42,10 @@ class Facility(Base):
     facility_id = Column("facility_id", Integer, primary_key=True)
     facility_name = Column("facility_name", String, nullable=False)
     facility_configurations: list[FacilityConfiguration] = relationship(
-        FacilityConfiguration, back_populates="facility", cascade="all, delete-orphan"
+        FacilityConfiguration,
+        back_populates="facility",
+        cascade="all, delete-orphan",
+        order_by=FacilityConfiguration.display_order,
     )
 
     def __init__(self, name: str) -> None:
@@ -58,6 +61,9 @@ class Facility(Base):
             "facilityConfigurations": (
                 [fc.__json__() for fc in self.facility_configurations] if self.facility_configurations else []
             ),
+            "configurationOptions": {
+                cat: [fc.__json__() for fc in fcs] for cat, fcs in self.configuration_options().items()
+            },
         }
 
     def __eq__(self, other):
-- 
GitLab