From eca7beefbde33d8f2d374efee944f9f09cb0a35d Mon Sep 17 00:00:00 2001 From: "XPS\\Micro" Date: Sun, 1 Feb 2026 16:40:20 +0100 Subject: [PATCH] fix: add backwards compatibility properties for container_id/container_port User model now provides container_id and container_port as properties that work with the new UserContainer relationship. This allows legacy code in api.py to continue working without modifications. The properties automatically: - Read from the primary (first) container - Create a primary container on first write - Maintain backwards compatibility with single-container API --- models.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/models.py b/models.py index 77395b9..9ce60e5 100644 --- a/models.py +++ b/models.py @@ -40,6 +40,52 @@ class User(UserMixin, db.Model): # Multi-Container Support containers = db.relationship('UserContainer', back_populates='user', cascade='all, delete-orphan') + @property + def container_id(self): + """Backwards compatibility: gibt ID des Primary Containers zurück""" + if self.containers: + return self.containers[0].container_id + return None + + @container_id.setter + def container_id(self, value): + """Backwards compatibility: setzt Primary Container ID""" + if not self.containers: + # Erstelle Primary Container wenn nicht vorhanden + from config import Config + primary = UserContainer( + user_id=self.id, + container_type='template-01', + template_image=Config.USER_TEMPLATE_IMAGE + ) + db.session.add(primary) + db.session.flush() + self.containers.append(primary) + self.containers[0].container_id = value + + @property + def container_port(self): + """Backwards compatibility: gibt Port des Primary Containers zurück""" + if self.containers: + return self.containers[0].container_port + return None + + @container_port.setter + def container_port(self, value): + """Backwards compatibility: setzt Primary Container Port""" + if not self.containers: + # Erstelle Primary Container wenn nicht vorhanden + from config import Config + primary = UserContainer( + user_id=self.id, + container_type='template-01', + template_image=Config.USER_TEMPLATE_IMAGE + ) + db.session.add(primary) + db.session.flush() + self.containers.append(primary) + self.containers[0].container_port = value + def to_dict(self): """Konvertiert User zu Dictionary fuer API-Responses""" return {