77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""
|
|
MongoDB Domain Models.
|
|
|
|
This module provides Pydantic models for domain management,
|
|
including domain history and access details.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Any, Dict, List, Optional
|
|
from pydantic import BaseModel, Field, ConfigDict, model_validator
|
|
|
|
from ApiLibrary import system_arrow
|
|
from Services.MongoDb.Models.action_models.base import MongoBaseModel, MongoDocument
|
|
|
|
|
|
class DomainData(MongoBaseModel):
|
|
"""Model for domain data.
|
|
|
|
Attributes:
|
|
user_uu_id: Unique identifier of the user
|
|
main_domain: Primary domain
|
|
other_domains_list: List of additional domains
|
|
extra_data: Additional domain-related data
|
|
"""
|
|
|
|
user_uu_id: str = Field(..., description="User's unique identifier")
|
|
main_domain: str = Field(..., description="Primary domain")
|
|
other_domains_list: List[str] = Field(
|
|
default_factory=list, description="List of additional domains"
|
|
)
|
|
extra_data: Optional[Dict[str, Any]] = Field(
|
|
default_factory=dict,
|
|
alias="extraData",
|
|
description="Additional domain-related data",
|
|
)
|
|
|
|
model_config = ConfigDict(
|
|
from_attributes=True, populate_by_name=True, validate_assignment=True
|
|
)
|
|
|
|
|
|
class DomainDocument(MongoDocument):
|
|
"""Model for domain-related documents."""
|
|
|
|
data: DomainData = Field(..., description="Domain data")
|
|
|
|
def update_main_domain(self, new_domain: str) -> None:
|
|
"""Update the main domain and move current to history.
|
|
|
|
Args:
|
|
new_domain: New main domain to set
|
|
"""
|
|
if self.data.main_domain and self.data.main_domain != new_domain:
|
|
if self.data.main_domain not in self.data.other_domains_list:
|
|
self.data.other_domains_list.append(self.data.main_domain)
|
|
self.data.main_domain = new_domain
|
|
|
|
|
|
class DomainDocumentCreate(MongoDocument):
|
|
"""Model for creating new domain documents."""
|
|
|
|
data: DomainData = Field(..., description="Initial domain data")
|
|
|
|
model_config = ConfigDict(
|
|
from_attributes=True, populate_by_name=True, validate_assignment=True
|
|
)
|
|
|
|
|
|
class DomainDocumentUpdate(MongoDocument):
|
|
"""Model for updating existing domain documents."""
|
|
|
|
data: DomainData = Field(..., description="Updated domain data")
|
|
|
|
model_config = ConfigDict(
|
|
from_attributes=True, populate_by_name=True, validate_assignment=True
|
|
)
|