Nuevos cambios en el servidor
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
|
||||
"""
|
||||
Category Model - ServiceManagerWeb
|
||||
"""
|
||||
from sqlalchemy import String, Text, Boolean, ForeignKey
|
||||
from sqlalchemy import String, Text, Boolean, ForeignKey, Column, Integer
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from typing import List, Optional
|
||||
import uuid
|
||||
|
||||
from app.core.database import Base
|
||||
from app.models.tenant import Tenant
|
||||
from app.models.ticket import Ticket
|
||||
|
||||
class Category(Base):
|
||||
__tablename__ = "categories"
|
||||
__tablename__ = "ticket_categories" # Updated table name
|
||||
|
||||
name: Mapped[str] = mapped_column(String(100), nullable=False)
|
||||
description: Mapped[Optional[str]] = mapped_column(Text)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
|
||||
# Optional: Tenant specific categories?
|
||||
tenant_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("tenants.id", ondelete="CASCADE"), nullable=True)
|
||||
|
||||
# Updated tenant_id to be required
|
||||
tenant_id: Mapped[uuid.UUID] = mapped_column(
|
||||
UUID(as_uuid=True),
|
||||
ForeignKey("tenants.id", ondelete="CASCADE"),
|
||||
nullable=False
|
||||
)
|
||||
|
||||
# Relationships
|
||||
tickets: Mapped[List["Ticket"]] = relationship("Ticket", back_populates="category")
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
"""
|
||||
System Model - ServiceManagerWeb
|
||||
"""
|
||||
@@ -19,7 +18,11 @@ class System(Base):
|
||||
# Relationships
|
||||
# If we want tickets to link to systems, we will add relationship in Ticket later or now.
|
||||
# We will assume Ticket links to System.
|
||||
tickets: Mapped[List["Ticket"]] = relationship("Ticket", back_populates="system")
|
||||
tickets: Mapped[List["Ticket"]] = relationship(
|
||||
"Ticket",
|
||||
back_populates="affected_system",
|
||||
foreign_keys="Ticket.affected_system_id"
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<System(id={self.id}, name='{self.name}')>"
|
||||
|
||||
@@ -54,15 +54,12 @@ class Tenant(Base):
|
||||
String(20),
|
||||
default=TenantStatus.ACTIVE
|
||||
)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
|
||||
# Relaciones
|
||||
users: Mapped[List["User"]] = relationship("User", back_populates="tenant")
|
||||
tickets: Mapped[List["Ticket"]] = relationship("Ticket", back_populates="tenant")
|
||||
categories: Mapped[List["Category"]] = relationship("Category", back_populates="tenant")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Tenant(id={self.id}, name='{self.name}', slug='{self.slug}')>"
|
||||
|
||||
@property
|
||||
def is_active(self) -> bool:
|
||||
"""Check if tenant is active."""
|
||||
return self.status == TenantStatus.ACTIVE
|
||||
return f"<Tenant(id={self.id}, name='{self.name}', slug='{self.slug}')>"
|
||||
@@ -4,11 +4,17 @@ Ticket Model - ServiceManagerWeb
|
||||
from sqlalchemy import String, ForeignKey, Text
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from sqlalchemy.dialects.postgresql import UUID, ENUM
|
||||
from typing import Optional
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
import enum
|
||||
import uuid
|
||||
|
||||
from app.core.database import Base
|
||||
from .tenant import Tenant
|
||||
from .system import System
|
||||
from .user import User
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from app.models.category import Category
|
||||
|
||||
class TicketStatus(str, enum.Enum):
|
||||
NEW = "NEW"
|
||||
@@ -43,7 +49,7 @@ class Ticket(Base):
|
||||
created_by: Mapped[uuid.UUID] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
assigned_to: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
||||
|
||||
system_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("systems.id"), nullable=True)
|
||||
affected_system_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("systems.id"), nullable=True)
|
||||
category_id: Mapped[Optional[uuid.UUID]] = mapped_column(UUID(as_uuid=True), ForeignKey("categories.id"), nullable=True)
|
||||
|
||||
# Relationships
|
||||
|
||||
Reference in New Issue
Block a user