Files
DevFlow/crates/df-project/src/manager.rs

75 lines
2.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! 项目管理器 — 项目的 CRUD 与生命周期管理
use serde::{Deserialize, Serialize};
use df_types::types::{IdeaId, Priority, ProjectId, ProjectStatus};
/// 项目实体
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Project {
/// 唯一 ID
pub id: ProjectId,
/// 项目名称
pub name: String,
/// 项目描述
pub description: String,
/// 当前状态
pub status: ProjectStatus,
/// 来源想法 ID可选如果是从想法晋升来的
pub idea_id: Option<IdeaId>,
/// 优先级
pub priority: Priority,
/// 标签
pub tags: Vec<String>,
/// 创建时间
pub created_at: chrono::DateTime<chrono::Utc>,
/// 更新时间
pub updated_at: chrono::DateTime<chrono::Utc>,
}
/// 创建项目的输入
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateProjectInput {
pub name: String,
pub description: String,
pub idea_id: Option<IdeaId>,
#[serde(default)]
pub priority: Priority,
#[serde(default)]
pub tags: Vec<String>,
}
/// 项目管理器
pub struct ProjectManager;
impl ProjectManager {
/// 创建新项目 — 构造领域实体(不落库);持久化由调用方经 storage 层 ProjectRecord 映射完成
/// (见 commands/idea.rs::promote_idea)。领域层不依赖 storage,保持分层。
pub fn create(input: CreateProjectInput) -> Project {
let now = chrono::Utc::now();
Project {
id: df_types::types::new_id(),
name: input.name,
description: input.description,
status: ProjectStatus::Planning,
idea_id: input.idea_id,
priority: input.priority,
tags: input.tags,
created_at: now,
updated_at: now,
}
}
/// 从想法创建项目
pub fn create_from_idea(name: String, description: String, idea_id: IdeaId) -> Project {
Self::create(CreateProjectInput {
name,
description,
idea_id: Some(idea_id),
priority: Priority::default(),
tags: Vec::new(),
})
}
}