153b38a62f
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 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 / Staging E2E Tests (push) Failing after 3m28s
CI/CD Pipeline / Canary Release to Production (push) Failing after 908h44m38s
CI/CD Pipeline / Deploy Production (push) Failing after 908h52m17s
CI/CD Pipeline / CI Gate (push) Failing after 908h52m18s
CI/CD Pipeline / Build Production Web Image (push) Failing after 908h52m18s
CI/CD Pipeline / Build Production API Image (push) Failing after 908h52m18s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 909h0m56s
CI/CD Pipeline / PR Build API Image (push) Failing after 909h0m58s
CI/CD Pipeline / Frontend Lint (push) Failing after 909h0m58s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 909h1m0s
CI/CD Pipeline / Production Browser E2E (push) Failing after 909h25m43s
CI/CD Pipeline / Build Production Worker Image (push) Failing after 909h25m44s
CI/CD Pipeline / PR Build Web Image (push) Failing after 909h34m22s
Co-authored-by: xiaoxia <dev@xiaoxiajianji.com> Co-committed-by: xiaoxia <dev@xiaoxiajianji.com>
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""封面模板 InMemory 仓储实现。"""
|
|
|
|
from packages.domain.cover_template import CoverTemplate
|
|
|
|
|
|
class InMemoryCoverTemplateRepository:
|
|
"""内存中的封面模板仓储,用于测试。"""
|
|
|
|
def __init__(self) -> None:
|
|
self._templates: dict[str, CoverTemplate] = {}
|
|
|
|
def create(self, template: CoverTemplate) -> CoverTemplate:
|
|
self._templates[template.id] = template
|
|
return template
|
|
|
|
def get(self, template_id: str) -> CoverTemplate | None:
|
|
return self._templates.get(template_id)
|
|
|
|
def list_for_user(self, user_id: str, skip: int = 0, limit: int = 100) -> list[CoverTemplate]:
|
|
"""列出系统模板 + 用户自己的模板。"""
|
|
visible = [t for t in self._templates.values() if t.is_system or t.user_id == user_id]
|
|
visible.sort(key=lambda t: (t.is_system, t.created_at), reverse=True)
|
|
return visible[skip : skip + limit]
|
|
|
|
def count_for_user(self, user_id: str) -> int:
|
|
return sum(1 for t in self._templates.values() if t.is_system or t.user_id == user_id)
|
|
|
|
def update(self, template: CoverTemplate) -> CoverTemplate:
|
|
if template.id not in self._templates:
|
|
raise ValueError(f"模板 {template.id} 不存在")
|
|
self._templates[template.id] = template
|
|
return template
|
|
|
|
def delete(self, template_id: str) -> bool:
|
|
if template_id in self._templates:
|
|
del self._templates[template_id]
|
|
return True
|
|
return False
|
|
|
|
def list_system_templates(self) -> list[CoverTemplate]:
|
|
return [t for t in self._templates.values() if t.is_system]
|