Files
xiaoxia 153b38a62f
CI/CD Pipeline / Check if frontend-only change (push) Has been skipped
CI/CD Pipeline / Frontend Lint (push) Has been skipped
CI/CD Pipeline / PR Build API Image (push) Has been skipped
CI/CD Pipeline / PR Build Web Image (push) Has been skipped
CI/CD Pipeline / PR Build Worker Image (push) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (push) Successful in 45s
CI/CD Pipeline / Validate - Migration (alembic) (push) Successful in 1m5s
CI/CD Pipeline / Build Staging Web Image (push) Successful in 2m24s
CI/CD Pipeline / Validate - Code Quality (push) Successful in 4m34s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 4m51s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m20s
CI/CD Pipeline / Integration Tests (push) Successful in 1m40s
CI/CD Pipeline / Unit Tests (push) Successful in 8m39s
CI/CD Pipeline / Build Production API Image (push) Has been skipped
CI/CD Pipeline / Build Production Web Image (push) Has been skipped
CI/CD Pipeline / Build Production Worker Image (push) Has been skipped
CI/CD Pipeline / CI Gate (push) Has been skipped
CI/CD Pipeline / Deploy Production (push) Has been skipped
CI/CD Pipeline / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Build Staging API Image (push) Successful in 11m49s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m19s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 36s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m9s
CI/CD Pipeline / Canary Release to Production (push) Has been skipped
CI/CD Pipeline / Staging E2E Tests (push) Failing after 3m28s
feat: 封面模板 CRUD API (#1323)
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com>
Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
2026-08-09 18:26:00 +08:00

79 lines
2.2 KiB
Python

"""封面模板领域实体。"""
from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Any
from uuid import uuid4
@dataclass(slots=True)
class CoverTemplate:
"""封面模板实体,支持系统预置和用户自定义。"""
id: str
user_id: str | None # None 表示系统模板
name: str
thumbnail_url: str
is_system: bool
config: dict[str, Any]
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
updated_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
@classmethod
def create_system(
cls,
name: str,
config: dict[str, Any] | None = None,
thumbnail_url: str = "",
) -> "CoverTemplate":
"""创建系统模板。"""
template_id = uuid4().hex
return cls(
id=template_id,
user_id=None,
name=name.strip(),
thumbnail_url=thumbnail_url,
is_system=True,
config=config or {},
)
@classmethod
def create_user(
cls,
user_id: str,
name: str,
config: dict[str, Any] | None = None,
thumbnail_url: str = "",
) -> "CoverTemplate":
"""创建用户自定义模板。"""
clean_name = name.strip()
if not clean_name:
raise ValueError("模板名称不能为空")
template_id = uuid4().hex
return cls(
id=template_id,
user_id=user_id,
name=clean_name,
thumbnail_url=thumbnail_url,
is_system=False,
config=config or {},
)
def update(
self,
name: str | None = None,
config: dict[str, Any] | None = None,
thumbnail_url: str | None = None,
) -> None:
"""更新模板属性。"""
if name is not None:
clean_name = name.strip()
if not clean_name:
raise ValueError("模板名称不能为空")
self.name = clean_name
if config is not None:
self.config = config
if thumbnail_url is not None:
self.thumbnail_url = thumbnail_url
self.updated_at = datetime.now(timezone.utc)