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
This commit is contained in:
parent
7b0d48ca32
commit
eca7beefbd
46
models.py
46
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user