Skip to main content

max / goingson

2.9 KB · 86 lines History Blame Raw
1 use super::{MilestoneId, NaiveDate, NewProject, Project, ProjectId, Result, UserId, async_trait};
2
3 /// Repository for project CRUD operations.
4 ///
5 /// All operations are scoped to a specific user for multi-tenancy support.
6 #[async_trait]
7 pub trait ProjectRepository: Send + Sync {
8 /// Lists all projects for a user.
9 async fn list_all(&self, user_id: UserId) -> Result<Vec<Project>>;
10
11 /// Retrieves a project by ID, returning `None` if not found.
12 async fn get_by_id(&self, id: ProjectId, user_id: UserId) -> Result<Option<Project>>;
13
14 /// Creates a new project.
15 async fn create(&self, user_id: UserId, project: NewProject) -> Result<Project>;
16
17 /// Restores a project verbatim from a backup, preserving its original ID
18 /// and `created_at`. Idempotent (`INSERT OR IGNORE`): re-restoring the same
19 /// backup is a no-op rather than a duplicate.
20 async fn restore(&self, user_id: UserId, project: &Project) -> Result<()>;
21
22 /// Updates an existing project, returning `None` if not found.
23 async fn update(
24 &self,
25 id: ProjectId,
26 user_id: UserId,
27 project: crate::models::UpdateProject,
28 ) -> Result<Option<Project>>;
29
30 /// Deletes a project, returning `true` if deleted.
31 async fn delete(&self, id: ProjectId, user_id: UserId) -> Result<bool>;
32
33 /// Finds a project by exact name match.
34 async fn find_by_name(&self, user_id: UserId, name: &str) -> Result<Option<Project>>;
35 }
36
37 /// Repository for milestone management within projects.
38 #[async_trait]
39 pub trait MilestoneRepository: Send + Sync {
40 /// Lists all milestones for a project, ordered by position.
41 async fn list_by_project(
42 &self,
43 project_id: ProjectId,
44 user_id: UserId,
45 ) -> Result<Vec<crate::models::Milestone>>;
46
47 /// Lists every milestone for a user across all projects (for full backup export).
48 async fn list_all(&self, user_id: UserId) -> Result<Vec<crate::models::Milestone>>;
49
50 /// Gets a milestone by ID.
51 async fn get_by_id(
52 &self,
53 id: MilestoneId,
54 user_id: UserId,
55 ) -> Result<Option<crate::models::Milestone>>;
56
57 /// Creates a new milestone.
58 async fn create(
59 &self,
60 user_id: UserId,
61 milestone: crate::models::NewMilestone,
62 ) -> Result<crate::models::Milestone>;
63
64 /// Updates an existing milestone.
65 async fn update(
66 &self,
67 id: MilestoneId,
68 user_id: UserId,
69 name: &str,
70 description: &str,
71 target_date: Option<NaiveDate>,
72 status: &crate::models::MilestoneStatus,
73 ) -> Result<Option<crate::models::Milestone>>;
74
75 /// Deletes a milestone.
76 async fn delete(&self, id: MilestoneId, user_id: UserId) -> Result<bool>;
77
78 /// Reorders milestones within a project.
79 async fn reorder(
80 &self,
81 project_id: ProjectId,
82 user_id: UserId,
83 milestone_ids: &[MilestoneId],
84 ) -> Result<()>;
85 }
86