Skip to main content

max / goingson

2.7 KB · 69 lines History Blame Raw
1 use super::*;
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(&self, project_id: ProjectId, user_id: UserId) -> Result<Vec<crate::models::Milestone>>;
42
43 /// Lists every milestone for a user across all projects (for full backup export).
44 async fn list_all(&self, user_id: UserId) -> Result<Vec<crate::models::Milestone>>;
45
46 /// Gets a milestone by ID.
47 async fn get_by_id(&self, id: MilestoneId, user_id: UserId) -> Result<Option<crate::models::Milestone>>;
48
49 /// Creates a new milestone.
50 async fn create(&self, user_id: UserId, milestone: crate::models::NewMilestone) -> Result<crate::models::Milestone>;
51
52 /// Updates an existing milestone.
53 async fn update(
54 &self,
55 id: MilestoneId,
56 user_id: UserId,
57 name: &str,
58 description: &str,
59 target_date: Option<NaiveDate>,
60 status: &crate::models::MilestoneStatus,
61 ) -> Result<Option<crate::models::Milestone>>;
62
63 /// Deletes a milestone.
64 async fn delete(&self, id: MilestoneId, user_id: UserId) -> Result<bool>;
65
66 /// Reorders milestones within a project.
67 async fn reorder(&self, project_id: ProjectId, user_id: UserId, milestone_ids: &[MilestoneId]) -> Result<()>;
68 }
69