356df4663e
Deploy / Staging E2E Tests (push) Has been cancelled
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
Deploy / Deploy Staging (push) Failing after 111h7m48s
CI/CD Pipeline / Frontend Lint (push) Failing after 111h7m57s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 111h7m57s
Task #105: 修复剪辑计划/模板页面报服务器繁忙 - templates.py: list_templates/get_template/list_categories 加 try/except - templates.py: 新增 POST /{template_id}/toggle-favorite 兼容端点 - edit_plans.py: list_plans 加 try/except,ai_tasks 加 ImportError 守卫 Task #106: 修复素材库诊断按钮 + 缩略图/视频URL - asset_diagnosis.py: get_project_asset_diagnosis 加 try/except - assets.py: 注入 storage_service,生成签名 file_url - asset.py schema: 新增 file_url 字段 - 视频素材 thumbnail_url 为空时复用 file_url 作为封面 其他: - edit_plans/generation_tasks 支持 source_edit_plan_id - Alembic 迁移 022: 两表加 source_edit_plan_id 字段
120 lines
4.1 KiB
Python
120 lines
4.1 KiB
Python
"""SQLAlchemy implementation of EditPlanRepository."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import List, Optional
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from packages.adapters.sqlalchemy_impl.models import EditPlanModel
|
|
from packages.domain.edit_plan import EditPlan, EditPlanStatus
|
|
|
|
|
|
class SQLAlchemyEditPlanRepository:
|
|
"""SQLAlchemy 剪辑计划仓储"""
|
|
|
|
def __init__(self, session: Session) -> None:
|
|
self.session = session
|
|
|
|
def list_by_template(
|
|
self,
|
|
template_id: str,
|
|
*,
|
|
status: Optional[EditPlanStatus] = None,
|
|
skip: int = 0,
|
|
limit: int = 50,
|
|
) -> List[EditPlan]:
|
|
"""按模板列出剪辑计划"""
|
|
query = self.session.query(EditPlanModel).filter(
|
|
EditPlanModel.template_id == template_id,
|
|
)
|
|
if status:
|
|
query = query.filter(EditPlanModel.status == status)
|
|
query = query.order_by(EditPlanModel.created_at.desc())
|
|
models = query.offset(skip).limit(limit).all()
|
|
return [self._model_to_entity(m) for m in models]
|
|
|
|
def list_all(
|
|
self,
|
|
*,
|
|
status: Optional[EditPlanStatus] = None,
|
|
skip: int = 0,
|
|
limit: int = 50,
|
|
) -> List[EditPlan]:
|
|
"""列出所有剪辑计划"""
|
|
query = self.session.query(EditPlanModel)
|
|
if status:
|
|
query = query.filter(EditPlanModel.status == status)
|
|
query = query.order_by(EditPlanModel.created_at.desc())
|
|
models = query.offset(skip).limit(limit).all()
|
|
return [self._model_to_entity(m) for m in models]
|
|
|
|
def get(self, plan_id: str) -> Optional[EditPlan]:
|
|
"""根据 ID 获取计划"""
|
|
model = self.session.query(EditPlanModel).filter(EditPlanModel.id == plan_id).first()
|
|
if model is None:
|
|
return None
|
|
return self._model_to_entity(model)
|
|
|
|
def create(self, plan: EditPlan) -> EditPlan:
|
|
"""创建计划"""
|
|
model = EditPlanModel(
|
|
id=plan.id,
|
|
template_id=plan.template_id,
|
|
name=plan.name,
|
|
status=plan.status,
|
|
total_duration=plan.total_duration,
|
|
source_edit_plan_id=plan.source_edit_plan_id or None,
|
|
config=plan.config,
|
|
)
|
|
self.session.add(model)
|
|
self.session.commit()
|
|
self.session.refresh(model)
|
|
return self._model_to_entity(model)
|
|
|
|
def update(self, plan: EditPlan) -> EditPlan:
|
|
"""更新计划"""
|
|
model = self.session.query(EditPlanModel).filter(EditPlanModel.id == plan.id).first()
|
|
if model is None:
|
|
raise ValueError(f"EditPlan {plan.id} not found")
|
|
model.template_id = plan.template_id
|
|
model.name = plan.name
|
|
model.status = plan.status
|
|
model.total_duration = plan.total_duration
|
|
model.source_edit_plan_id = plan.source_edit_plan_id or None
|
|
model.config = plan.config
|
|
model.updated_at = plan.updated_at
|
|
self.session.commit()
|
|
self.session.refresh(model)
|
|
return self._model_to_entity(model)
|
|
|
|
def delete(self, plan_id: str) -> bool:
|
|
"""删除计划"""
|
|
model = self.session.query(EditPlanModel).filter(EditPlanModel.id == plan_id).first()
|
|
if model is None:
|
|
return False
|
|
self.session.delete(model)
|
|
self.session.commit()
|
|
return True
|
|
|
|
def count(self, *, status: Optional[EditPlanStatus] = None) -> int:
|
|
"""统计计划数量"""
|
|
query = self.session.query(EditPlanModel)
|
|
if status:
|
|
query = query.filter(EditPlanModel.status == status)
|
|
return query.count()
|
|
|
|
@staticmethod
|
|
def _model_to_entity(model: EditPlanModel) -> EditPlan:
|
|
return EditPlan(
|
|
id=model.id,
|
|
template_id=model.template_id,
|
|
name=model.name,
|
|
status=EditPlanStatus(model.status) if model.status else EditPlanStatus.DRAFT,
|
|
total_duration=model.total_duration or 0.0,
|
|
source_edit_plan_id=model.source_edit_plan_id or "",
|
|
config=model.config or {},
|
|
created_at=model.created_at,
|
|
updated_at=model.updated_at,
|
|
)
|