| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
use async_trait::async_trait; |
| 7 |
use chrono::{DateTime, NaiveDate, Utc}; |
| 8 |
use std::collections::HashSet; |
| 9 |
use crate::id_types::{ |
| 10 |
AnnotationId, AttachmentId, ContactEmailId, ContactId, ContactPhoneId, CustomFieldId, |
| 11 |
EmailAccountId, EmailId, EventId, MilestoneId, ProjectId, SavedViewId, |
| 12 |
SocialHandleId, SubtaskId, SyncAccountId, TaskId, UserId, |
| 13 |
}; |
| 14 |
use uuid::Uuid; |
| 15 |
|
| 16 |
use crate::contact::{ |
| 17 |
Contact, ContactCustomField, ContactEmail, ContactPhone, NewContact, NewContactCustomField, |
| 18 |
NewContactEmail, NewContactPhone, NewSocialHandle, SocialHandle, UpdateContact, |
| 19 |
}; |
| 20 |
use crate::error::CoreError; |
| 21 |
use crate::models::{ |
| 22 |
Annotation, Attachment, Email, EmailAccount, EmailAuthType, EmailThread, Event, |
| 23 |
FolderSyncState, NewAttachment, NewEmail, NewEmailWithTracking, NewEvent, NewProject, |
| 24 |
NewSavedView, NewTask, Project, SavedView, Subtask, Task, TaskFilterQuery, TimeSession, |
| 25 |
TimeTrackingSummary, UpdateTask, User, |
| 26 |
}; |
| 27 |
|
| 28 |
|
| 29 |
pub type Result<T> = std::result::Result<T, CoreError>; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#[async_trait] |
| 35 |
pub trait ProjectRepository: Send + Sync { |
| 36 |
|
| 37 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<Project>>; |
| 38 |
|
| 39 |
|
| 40 |
async fn get_by_id(&self, id: ProjectId, user_id: UserId) -> Result<Option<Project>>; |
| 41 |
|
| 42 |
|
| 43 |
async fn create(&self, user_id: UserId, project: NewProject) -> Result<Project>; |
| 44 |
|
| 45 |
|
| 46 |
async fn update( |
| 47 |
&self, |
| 48 |
id: ProjectId, |
| 49 |
user_id: UserId, |
| 50 |
project: crate::models::UpdateProject, |
| 51 |
) -> Result<Option<Project>>; |
| 52 |
|
| 53 |
|
| 54 |
async fn delete(&self, id: ProjectId, user_id: UserId) -> Result<bool>; |
| 55 |
|
| 56 |
|
| 57 |
async fn find_by_name(&self, user_id: UserId, name: &str) -> Result<Option<Project>>; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#[async_trait] |
| 65 |
pub trait TaskRepository: Send + Sync { |
| 66 |
|
| 67 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<Task>>; |
| 68 |
|
| 69 |
|
| 70 |
async fn list_by_project(&self, user_id: UserId, project_id: ProjectId) -> Result<Vec<Task>>; |
| 71 |
|
| 72 |
|
| 73 |
async fn list_by_contact(&self, user_id: UserId, contact_id: ContactId) -> Result<Vec<Task>>; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
async fn list_filtered(&self, user_id: UserId, query: TaskFilterQuery) -> Result<(Vec<Task>, i64)>; |
| 78 |
|
| 79 |
|
| 80 |
async fn get_by_id(&self, id: TaskId, user_id: UserId) -> Result<Option<Task>>; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
async fn get_update_context(&self, id: TaskId, user_id: UserId) -> Result<Option<crate::models::TaskUpdateContext>>; |
| 85 |
|
| 86 |
|
| 87 |
async fn create(&self, user_id: UserId, task: NewTask) -> Result<Task>; |
| 88 |
|
| 89 |
|
| 90 |
async fn update(&self, id: TaskId, user_id: UserId, task: UpdateTask) -> Result<Option<Task>>; |
| 91 |
|
| 92 |
|
| 93 |
async fn delete(&self, id: TaskId, user_id: UserId) -> Result<bool>; |
| 94 |
|
| 95 |
|
| 96 |
async fn start(&self, id: TaskId, user_id: UserId) -> Result<bool>; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
async fn complete(&self, id: TaskId, user_id: UserId) -> Result<Option<Task>>; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
async fn complete_recurring(&self, id: TaskId, user_id: UserId, next: Option<NewTask>) -> Result<(Option<Task>, Option<Task>)>; |
| 107 |
|
| 108 |
|
| 109 |
async fn count_incomplete_by_milestone(&self, milestone_id: MilestoneId, user_id: UserId) -> Result<i64>; |
| 110 |
|
| 111 |
|
| 112 |
async fn get_annotations_for_task(&self, task_id: TaskId) -> Result<Vec<Annotation>>; |
| 113 |
|
| 114 |
|
| 115 |
async fn add_annotation(&self, task_id: TaskId, user_id: UserId, note: &str) -> Result<Option<Annotation>>; |
| 116 |
|
| 117 |
|
| 118 |
async fn delete_annotation(&self, annotation_id: AnnotationId, user_id: UserId) -> Result<bool>; |
| 119 |
|
| 120 |
|
| 121 |
async fn get_subtasks_for_task(&self, task_id: TaskId) -> Result<Vec<Subtask>>; |
| 122 |
|
| 123 |
|
| 124 |
async fn add_subtask(&self, task_id: TaskId, user_id: UserId, text: &str) -> Result<Option<Subtask>>; |
| 125 |
|
| 126 |
|
| 127 |
async fn toggle_subtask(&self, subtask_id: SubtaskId, user_id: UserId) -> Result<Option<Subtask>>; |
| 128 |
|
| 129 |
|
| 130 |
async fn update_subtask(&self, subtask_id: SubtaskId, user_id: UserId, text: &str) -> Result<Option<Subtask>>; |
| 131 |
|
| 132 |
|
| 133 |
async fn delete_subtask(&self, subtask_id: SubtaskId, user_id: UserId) -> Result<bool>; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
async fn add_subtask_link(&self, task_id: TaskId, user_id: UserId, linked_task_id: TaskId) -> Result<Option<Subtask>>; |
| 141 |
|
| 142 |
|
| 143 |
async fn snooze(&self, id: TaskId, user_id: UserId, until: DateTime<Utc>) -> Result<Option<Task>>; |
| 144 |
|
| 145 |
|
| 146 |
async fn unsnooze(&self, id: TaskId, user_id: UserId) -> Result<Option<Task>>; |
| 147 |
|
| 148 |
|
| 149 |
async fn list_snoozed(&self, user_id: UserId) -> Result<Vec<Task>>; |
| 150 |
|
| 151 |
|
| 152 |
async fn mark_waiting(&self, id: TaskId, user_id: UserId, expected_response: Option<DateTime<Utc>>) -> Result<Option<Task>>; |
| 153 |
|
| 154 |
|
| 155 |
async fn clear_waiting(&self, id: TaskId, user_id: UserId) -> Result<Option<Task>>; |
| 156 |
|
| 157 |
|
| 158 |
async fn list_waiting(&self, user_id: UserId) -> Result<Vec<Task>>; |
| 159 |
|
| 160 |
|
| 161 |
async fn list_scheduled_for_date(&self, user_id: UserId, date: NaiveDate) -> Result<Vec<Task>>; |
| 162 |
|
| 163 |
|
| 164 |
async fn list_unscheduled_due_on_date(&self, user_id: UserId, date: NaiveDate) -> Result<Vec<Task>>; |
| 165 |
|
| 166 |
|
| 167 |
async fn update_schedule(&self, id: TaskId, user_id: UserId, start: Option<DateTime<Utc>>, duration: Option<i32>) -> Result<Option<Task>>; |
| 168 |
|
| 169 |
|
| 170 |
async fn set_focus(&self, id: TaskId, user_id: UserId, is_focus: bool) -> Result<Option<Task>>; |
| 171 |
|
| 172 |
|
| 173 |
async fn list_focused(&self, user_id: UserId) -> Result<Vec<Task>>; |
| 174 |
|
| 175 |
|
| 176 |
async fn clear_all_focus(&self, user_id: UserId) -> Result<u64>; |
| 177 |
|
| 178 |
|
| 179 |
async fn list_completed_between(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<Task>>; |
| 180 |
|
| 181 |
|
| 182 |
async fn list_became_overdue_between(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<Task>>; |
| 183 |
|
| 184 |
|
| 185 |
async fn list_due_between(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<Task>>; |
| 186 |
|
| 187 |
|
| 188 |
async fn list_created_between(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<Task>>; |
| 189 |
|
| 190 |
|
| 191 |
async fn list_available_for_focus(&self, user_id: UserId, limit: i64) -> Result<Vec<Task>>; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
async fn start_timer(&self, task_id: TaskId, user_id: UserId) -> Result<TimeSession>; |
| 197 |
|
| 198 |
|
| 199 |
async fn stop_timer(&self, task_id: TaskId, user_id: UserId) -> Result<Option<TimeSession>>; |
| 200 |
|
| 201 |
|
| 202 |
async fn discard_timer(&self, task_id: TaskId, user_id: UserId) -> Result<bool>; |
| 203 |
|
| 204 |
|
| 205 |
async fn get_active_timer(&self, user_id: UserId) -> Result<Option<(TimeSession, String)>>; |
| 206 |
|
| 207 |
|
| 208 |
async fn list_time_sessions(&self, task_id: TaskId, user_id: UserId) -> Result<Vec<TimeSession>>; |
| 209 |
|
| 210 |
|
| 211 |
async fn log_manual_time(&self, task_id: TaskId, user_id: UserId, minutes: i32, date: DateTime<Utc>) -> Result<TimeSession>; |
| 212 |
|
| 213 |
|
| 214 |
async fn get_time_summary(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<TimeTrackingSummary>>; |
| 215 |
|
| 216 |
|
| 217 |
async fn list_recurrence_chain(&self, root_id: TaskId, user_id: UserId) -> Result<Vec<Task>>; |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
#[async_trait] |
| 230 |
pub trait EventRepository: Send + Sync { |
| 231 |
|
| 232 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<Event>>; |
| 233 |
|
| 234 |
|
| 235 |
async fn list_by_project(&self, user_id: UserId, project_id: ProjectId) -> Result<Vec<Event>>; |
| 236 |
|
| 237 |
|
| 238 |
async fn list_by_contact(&self, user_id: UserId, contact_id: ContactId) -> Result<Vec<Event>>; |
| 239 |
|
| 240 |
|
| 241 |
async fn get_by_id(&self, id: EventId, user_id: UserId) -> Result<Option<Event>>; |
| 242 |
|
| 243 |
|
| 244 |
async fn create(&self, user_id: UserId, event: NewEvent) -> Result<Event>; |
| 245 |
|
| 246 |
|
| 247 |
async fn update(&self, id: EventId, user_id: UserId, event: crate::models::UpdateEvent) -> Result<Option<Event>>; |
| 248 |
|
| 249 |
|
| 250 |
async fn delete(&self, id: EventId, user_id: UserId) -> Result<bool>; |
| 251 |
|
| 252 |
|
| 253 |
async fn delete_many(&self, ids: &[EventId], user_id: UserId) -> Result<u64>; |
| 254 |
|
| 255 |
|
| 256 |
async fn get_upcoming(&self, user_id: UserId, days: i64) -> Result<Vec<Event>>; |
| 257 |
|
| 258 |
|
| 259 |
async fn get_by_linked_task(&self, user_id: UserId, task_id: TaskId) -> Result<Option<Event>>; |
| 260 |
|
| 261 |
|
| 262 |
async fn delete_by_linked_task(&self, user_id: UserId, task_id: TaskId) -> Result<bool>; |
| 263 |
|
| 264 |
|
| 265 |
async fn list_for_date(&self, user_id: UserId, date: NaiveDate) -> Result<Vec<Event>>; |
| 266 |
|
| 267 |
|
| 268 |
async fn list_between(&self, user_id: UserId, start: DateTime<Utc>, end: DateTime<Utc>) -> Result<Vec<Event>>; |
| 269 |
|
| 270 |
|
| 271 |
async fn list_recurring(&self, user_id: UserId) -> Result<Vec<Event>>; |
| 272 |
|
| 273 |
|
| 274 |
async fn find_by_external_id(&self, source: &str, ext_id: &str, user_id: UserId) -> Result<Option<Event>>; |
| 275 |
|
| 276 |
|
| 277 |
async fn snooze(&self, id: EventId, user_id: UserId, until: DateTime<Utc>) -> Result<Option<Event>>; |
| 278 |
|
| 279 |
|
| 280 |
async fn unsnooze(&self, id: EventId, user_id: UserId) -> Result<Option<Event>>; |
| 281 |
|
| 282 |
|
| 283 |
async fn list_snoozed(&self, user_id: UserId) -> Result<Vec<Event>>; |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
#[async_trait] |
| 291 |
pub trait EmailRepository: Send + Sync { |
| 292 |
|
| 293 |
async fn list_all(&self, user_id: UserId, include_archived: bool) -> Result<Vec<Email>>; |
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
async fn list_threaded(&self, user_id: UserId, include_archived: bool, offset: Option<i64>, limit: Option<i64>, folder: Option<&str>, label: Option<&str>) -> Result<(Vec<EmailThread>, i64)>; |
| 300 |
|
| 301 |
|
| 302 |
async fn list_by_project(&self, user_id: UserId, project_id: ProjectId) -> Result<Vec<Email>>; |
| 303 |
|
| 304 |
|
| 305 |
async fn list_by_addresses(&self, user_id: UserId, addresses: &[&str]) -> Result<Vec<Email>>; |
| 306 |
|
| 307 |
|
| 308 |
async fn list_unlinked(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 309 |
|
| 310 |
|
| 311 |
async fn get_by_id(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 312 |
|
| 313 |
|
| 314 |
async fn create(&self, user_id: UserId, email: NewEmail) -> Result<Email>; |
| 315 |
|
| 316 |
|
| 317 |
async fn create_with_tracking(&self, user_id: UserId, email: NewEmailWithTracking) -> Result<Email>; |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
async fn create_with_tracking_batch(&self, user_id: UserId, emails: Vec<NewEmailWithTracking>) -> Result<usize>; |
| 322 |
|
| 323 |
|
| 324 |
async fn delete(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 325 |
|
| 326 |
|
| 327 |
async fn mark_read(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 328 |
|
| 329 |
|
| 330 |
async fn mark_unread(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 331 |
|
| 332 |
|
| 333 |
async fn archive(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 334 |
|
| 335 |
|
| 336 |
async fn unarchive(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 337 |
|
| 338 |
|
| 339 |
async fn update_source_folder(&self, id: EmailId, user_id: UserId, new_folder: &str) -> Result<bool>; |
| 340 |
|
| 341 |
|
| 342 |
async fn mark_all_read(&self, user_id: UserId) -> Result<u64>; |
| 343 |
|
| 344 |
|
| 345 |
async fn link_to_project(&self, id: EmailId, user_id: UserId, project_id: Option<ProjectId>) -> Result<bool>; |
| 346 |
|
| 347 |
|
| 348 |
async fn count_unread(&self, user_id: UserId) -> Result<i64>; |
| 349 |
|
| 350 |
|
| 351 |
async fn exists_by_message_id(&self, user_id: UserId, message_id: &str) -> Result<bool>; |
| 352 |
|
| 353 |
|
| 354 |
async fn exists_by_message_ids(&self, user_id: UserId, message_ids: &[&str]) -> Result<HashSet<String>>; |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
async fn exists_as_senders(&self, user_id: UserId, addresses: &[&str]) -> Result<HashSet<String>>; |
| 359 |
|
| 360 |
|
| 361 |
async fn snooze(&self, id: EmailId, user_id: UserId, until: DateTime<Utc>) -> Result<Option<Email>>; |
| 362 |
|
| 363 |
|
| 364 |
async fn unsnooze(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 365 |
|
| 366 |
|
| 367 |
async fn list_snoozed(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 368 |
|
| 369 |
|
| 370 |
async fn mark_waiting(&self, id: EmailId, user_id: UserId, expected_response: Option<DateTime<Utc>>) -> Result<Option<Email>>; |
| 371 |
|
| 372 |
|
| 373 |
async fn clear_waiting(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 374 |
|
| 375 |
|
| 376 |
async fn list_waiting(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 377 |
|
| 378 |
|
| 379 |
async fn list_by_thread(&self, user_id: UserId, thread_id: &str) -> Result<Vec<Email>>; |
| 380 |
|
| 381 |
|
| 382 |
async fn get_by_message_id(&self, user_id: UserId, message_id: &str) -> Result<Option<Email>>; |
| 383 |
|
| 384 |
|
| 385 |
async fn update_labels(&self, id: EmailId, user_id: UserId, labels: &[String]) -> Result<Option<Email>>; |
| 386 |
|
| 387 |
|
| 388 |
async fn list_folders(&self, user_id: UserId) -> Result<Vec<String>>; |
| 389 |
|
| 390 |
|
| 391 |
async fn list_labels(&self, user_id: UserId) -> Result<Vec<String>>; |
| 392 |
|
| 393 |
|
| 394 |
async fn list_drafts(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 395 |
|
| 396 |
|
| 397 |
#[allow(clippy::too_many_arguments)] |
| 398 |
async fn save_draft(&self, id: EmailId, user_id: UserId, from: &str, to: &str, cc: Option<&str>, bcc: Option<&str>, subject: &str, body: &str, account_id: Option<EmailAccountId>, in_reply_to: Option<&str>, references: Option<&str>, thread_id: Option<&str>) -> Result<Email>; |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
#[async_trait] |
| 403 |
pub trait UserRepository: Send + Sync { |
| 404 |
|
| 405 |
async fn create(&self, email: &str, password: &str, display_name: &str) -> Result<User>; |
| 406 |
|
| 407 |
|
| 408 |
async fn find_by_email(&self, email: &str) -> Result<Option<User>>; |
| 409 |
|
| 410 |
|
| 411 |
async fn authenticate(&self, email: &str, password: &str) -> Result<Option<User>>; |
| 412 |
|
| 413 |
|
| 414 |
async fn update_last_login(&self, user_id: UserId) -> Result<()>; |
| 415 |
} |
| 416 |
|
| 417 |
|
| 418 |
#[allow(clippy::too_many_arguments)] |
| 419 |
#[async_trait] |
| 420 |
pub trait EmailAccountRepository: Send + Sync { |
| 421 |
|
| 422 |
async fn list_by_user(&self, user_id: UserId) -> Result<Vec<EmailAccount>>; |
| 423 |
|
| 424 |
|
| 425 |
async fn get_by_id(&self, id: EmailAccountId, user_id: UserId) -> Result<Option<EmailAccount>>; |
| 426 |
|
| 427 |
|
| 428 |
async fn create( |
| 429 |
&self, |
| 430 |
user_id: UserId, |
| 431 |
account_name: &str, |
| 432 |
email_address: &str, |
| 433 |
imap_server: &str, |
| 434 |
imap_port: i32, |
| 435 |
smtp_server: &str, |
| 436 |
smtp_port: i32, |
| 437 |
username: &str, |
| 438 |
password: &str, |
| 439 |
use_tls: bool, |
| 440 |
archive_folder_name: Option<&str>, |
| 441 |
) -> Result<EmailAccount>; |
| 442 |
|
| 443 |
|
| 444 |
async fn create_oauth( |
| 445 |
&self, |
| 446 |
user_id: UserId, |
| 447 |
account_name: &str, |
| 448 |
email_address: &str, |
| 449 |
access_token: &str, |
| 450 |
refresh_token: &str, |
| 451 |
expires_at: DateTime<Utc>, |
| 452 |
jmap_session_url: &str, |
| 453 |
jmap_account_id: &str, |
| 454 |
) -> Result<EmailAccount>; |
| 455 |
|
| 456 |
|
| 457 |
async fn create_oauth_imap( |
| 458 |
&self, |
| 459 |
user_id: UserId, |
| 460 |
account_name: &str, |
| 461 |
email_address: &str, |
| 462 |
auth_type: EmailAuthType, |
| 463 |
access_token: &str, |
| 464 |
refresh_token: &str, |
| 465 |
expires_at: DateTime<Utc>, |
| 466 |
imap_server: &str, |
| 467 |
imap_port: i32, |
| 468 |
smtp_server: &str, |
| 469 |
smtp_port: i32, |
| 470 |
) -> Result<EmailAccount>; |
| 471 |
|
| 472 |
|
| 473 |
async fn update( |
| 474 |
&self, |
| 475 |
id: EmailAccountId, |
| 476 |
user_id: UserId, |
| 477 |
account_name: &str, |
| 478 |
email_address: &str, |
| 479 |
imap_server: &str, |
| 480 |
imap_port: i32, |
| 481 |
smtp_server: &str, |
| 482 |
smtp_port: i32, |
| 483 |
username: &str, |
| 484 |
password: Option<&str>, |
| 485 |
use_tls: bool, |
| 486 |
archive_folder_name: Option<&str>, |
| 487 |
) -> Result<Option<EmailAccount>>; |
| 488 |
|
| 489 |
|
| 490 |
async fn update_oauth_tokens( |
| 491 |
&self, |
| 492 |
id: EmailAccountId, |
| 493 |
user_id: UserId, |
| 494 |
access_token: &str, |
| 495 |
refresh_token: Option<&str>, |
| 496 |
expires_at: DateTime<Utc>, |
| 497 |
) -> Result<Option<EmailAccount>>; |
| 498 |
|
| 499 |
|
| 500 |
async fn update_jmap_session( |
| 501 |
&self, |
| 502 |
id: EmailAccountId, |
| 503 |
user_id: UserId, |
| 504 |
session_url: &str, |
| 505 |
account_id: &str, |
| 506 |
) -> Result<Option<EmailAccount>>; |
| 507 |
|
| 508 |
|
| 509 |
async fn delete(&self, id: EmailAccountId, user_id: UserId) -> Result<bool>; |
| 510 |
|
| 511 |
|
| 512 |
async fn update_last_sync(&self, id: EmailAccountId, user_id: UserId) -> Result<bool>; |
| 513 |
|
| 514 |
|
| 515 |
async fn update_sync_interval(&self, id: EmailAccountId, user_id: UserId, interval_minutes: Option<i32>) -> Result<Option<EmailAccount>>; |
| 516 |
|
| 517 |
|
| 518 |
async fn update_signature(&self, id: EmailAccountId, user_id: UserId, signature: Option<&str>) -> Result<Option<EmailAccount>>; |
| 519 |
|
| 520 |
|
| 521 |
async fn update_notify_new_emails(&self, id: EmailAccountId, user_id: UserId, enabled: bool) -> Result<Option<EmailAccount>>; |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
async fn list_accounts_needing_sync(&self, user_id: UserId) -> Result<Vec<EmailAccount>>; |
| 526 |
|
| 527 |
|
| 528 |
async fn get_folder_sync_state(&self, account_id: EmailAccountId, folder: &str) -> Result<Option<FolderSyncState>>; |
| 529 |
|
| 530 |
|
| 531 |
async fn upsert_folder_sync_state(&self, account_id: EmailAccountId, folder: &str, uid_validity: u32, last_seen_uid: u32) -> Result<()>; |
| 532 |
|
| 533 |
|
| 534 |
async fn delete_folder_sync_state(&self, account_id: EmailAccountId, folder: &str) -> Result<()>; |
| 535 |
} |
| 536 |
|
| 537 |
|
| 538 |
#[derive(Debug, Clone, serde::Serialize)] |
| 539 |
pub struct DashboardStats { |
| 540 |
|
| 541 |
pub tasks_due_today: i64, |
| 542 |
|
| 543 |
pub tasks_due_this_week: i64, |
| 544 |
|
| 545 |
pub overdue_count: i64, |
| 546 |
|
| 547 |
pub unread_emails: i64, |
| 548 |
|
| 549 |
pub upcoming_events: i64, |
| 550 |
|
| 551 |
pub active_projects: i64, |
| 552 |
|
| 553 |
pub high_urgency_tasks: Vec<HighUrgencyTask>, |
| 554 |
} |
| 555 |
|
| 556 |
|
| 557 |
#[derive(Debug, Clone, serde::Serialize)] |
| 558 |
pub struct HighUrgencyTask { |
| 559 |
|
| 560 |
pub id: String, |
| 561 |
|
| 562 |
pub description: String, |
| 563 |
|
| 564 |
pub urgency: f64, |
| 565 |
|
| 566 |
pub status: String, |
| 567 |
|
| 568 |
pub due: Option<String>, |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
#[async_trait] |
| 573 |
pub trait StatsRepository: Send + Sync { |
| 574 |
|
| 575 |
async fn get_dashboard_stats(&self, user_id: UserId) -> Result<DashboardStats>; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] |
| 580 |
#[serde(rename_all = "lowercase")] |
| 581 |
pub enum SearchResultType { |
| 582 |
|
| 583 |
Task, |
| 584 |
|
| 585 |
Email, |
| 586 |
|
| 587 |
Project, |
| 588 |
|
| 589 |
Event, |
| 590 |
|
| 591 |
Contact, |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
#[derive(Debug, Clone, serde::Serialize)] |
| 596 |
pub struct SearchResultItem { |
| 597 |
|
| 598 |
pub id: Uuid, |
| 599 |
|
| 600 |
pub result_type: SearchResultType, |
| 601 |
|
| 602 |
pub title: String, |
| 603 |
|
| 604 |
pub snippet: Option<String>, |
| 605 |
|
| 606 |
pub project_id: Option<ProjectId>, |
| 607 |
|
| 608 |
pub project_name: Option<String>, |
| 609 |
|
| 610 |
pub rank: f64, |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
#[derive(Debug, Clone, Default)] |
| 615 |
pub struct SearchQuery { |
| 616 |
|
| 617 |
pub query: String, |
| 618 |
|
| 619 |
pub types: Option<Vec<SearchResultType>>, |
| 620 |
|
| 621 |
pub project_id: Option<ProjectId>, |
| 622 |
|
| 623 |
pub project_name: Option<String>, |
| 624 |
|
| 625 |
pub date_from: Option<DateTime<Utc>>, |
| 626 |
|
| 627 |
pub date_to: Option<DateTime<Utc>>, |
| 628 |
|
| 629 |
pub limit: Option<i64>, |
| 630 |
|
| 631 |
pub offset: Option<i64>, |
| 632 |
|
| 633 |
pub is_filters: Vec<crate::search_parser::IsFilter>, |
| 634 |
|
| 635 |
pub priority: Option<crate::models::Priority>, |
| 636 |
|
| 637 |
pub tags_include: Vec<String>, |
| 638 |
|
| 639 |
pub tags_exclude: Vec<String>, |
| 640 |
} |
| 641 |
|
| 642 |
impl SearchQuery { |
| 643 |
|
| 644 |
pub fn new(query: impl Into<String>) -> Self { |
| 645 |
Self { |
| 646 |
query: query.into(), |
| 647 |
types: None, |
| 648 |
project_id: None, |
| 649 |
project_name: None, |
| 650 |
date_from: None, |
| 651 |
date_to: None, |
| 652 |
limit: Some(50), |
| 653 |
offset: None, |
| 654 |
is_filters: Vec::new(), |
| 655 |
priority: None, |
| 656 |
tags_include: Vec::new(), |
| 657 |
tags_exclude: Vec::new(), |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
|
| 662 |
pub fn with_types(mut self, types: Vec<SearchResultType>) -> Self { |
| 663 |
self.types = Some(types); |
| 664 |
self |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
pub fn with_project(mut self, project_id: ProjectId) -> Self { |
| 669 |
self.project_id = Some(project_id); |
| 670 |
self |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
pub fn with_project_name(mut self, name: impl Into<String>) -> Self { |
| 675 |
self.project_name = Some(name.into()); |
| 676 |
self |
| 677 |
} |
| 678 |
|
| 679 |
|
| 680 |
pub fn with_limit(mut self, limit: i64) -> Self { |
| 681 |
self.limit = Some(limit); |
| 682 |
self |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
pub fn with_offset(mut self, offset: i64) -> Self { |
| 687 |
self.offset = Some(offset); |
| 688 |
self |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
pub fn with_date_from(mut self, date: DateTime<Utc>) -> Self { |
| 693 |
self.date_from = Some(date); |
| 694 |
self |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
pub fn with_date_to(mut self, date: DateTime<Utc>) -> Self { |
| 699 |
self.date_to = Some(date); |
| 700 |
self |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
pub fn with_is_filters(mut self, filters: Vec<crate::search_parser::IsFilter>) -> Self { |
| 705 |
self.is_filters = filters; |
| 706 |
self |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
pub fn with_priority(mut self, priority: crate::models::Priority) -> Self { |
| 711 |
self.priority = Some(priority); |
| 712 |
self |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
pub fn with_tags_include(mut self, tags: Vec<String>) -> Self { |
| 717 |
self.tags_include = tags; |
| 718 |
self |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
pub fn with_tags_exclude(mut self, tags: Vec<String>) -> Self { |
| 723 |
self.tags_exclude = tags; |
| 724 |
self |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
#[async_trait] |
| 730 |
pub trait SearchRepository: Send + Sync { |
| 731 |
|
| 732 |
|
| 733 |
async fn search(&self, user_id: UserId, query: SearchQuery) -> Result<(Vec<SearchResultItem>, usize)>; |
| 734 |
} |
| 735 |
|
| 736 |
|
| 737 |
#[async_trait] |
| 738 |
pub trait SavedViewRepository: Send + Sync { |
| 739 |
|
| 740 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<SavedView>>; |
| 741 |
|
| 742 |
|
| 743 |
async fn list_pinned(&self, user_id: UserId) -> Result<Vec<SavedView>>; |
| 744 |
|
| 745 |
|
| 746 |
async fn get_by_id(&self, id: SavedViewId, user_id: UserId) -> Result<Option<SavedView>>; |
| 747 |
|
| 748 |
|
| 749 |
async fn create(&self, user_id: UserId, view: NewSavedView) -> Result<SavedView>; |
| 750 |
|
| 751 |
|
| 752 |
async fn update(&self, id: SavedViewId, user_id: UserId, view: NewSavedView) -> Result<Option<SavedView>>; |
| 753 |
|
| 754 |
|
| 755 |
async fn delete(&self, id: SavedViewId, user_id: UserId) -> Result<bool>; |
| 756 |
|
| 757 |
|
| 758 |
async fn toggle_pinned(&self, id: SavedViewId, user_id: UserId) -> Result<Option<SavedView>>; |
| 759 |
|
| 760 |
|
| 761 |
async fn update_position(&self, id: SavedViewId, user_id: UserId, position: i32) -> Result<Option<SavedView>>; |
| 762 |
} |
| 763 |
|
| 764 |
|
| 765 |
#[async_trait] |
| 766 |
pub trait WeeklyReviewRepository: Send + Sync { |
| 767 |
|
| 768 |
async fn get_for_week(&self, user_id: UserId, week_start: NaiveDate) -> Result<Option<crate::models::WeeklyReview>>; |
| 769 |
|
| 770 |
|
| 771 |
async fn upsert(&self, user_id: UserId, week_start: NaiveDate, notes: &str) -> Result<crate::models::WeeklyReview>; |
| 772 |
|
| 773 |
|
| 774 |
async fn is_current_week_completed(&self, user_id: UserId) -> Result<bool>; |
| 775 |
|
| 776 |
|
| 777 |
async fn set_vacation_days(&self, user_id: UserId, week_start: NaiveDate, days: &[u8]) -> Result<()>; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
#[async_trait] |
| 782 |
pub trait DailyNoteRepository: Send + Sync { |
| 783 |
|
| 784 |
async fn get_by_date(&self, user_id: UserId, date: NaiveDate) -> Result<Option<crate::models::DailyNote>>; |
| 785 |
|
| 786 |
|
| 787 |
async fn upsert(&self, user_id: UserId, date: NaiveDate, went_well: &str, could_improve: &str, is_reviewed: bool) -> Result<crate::models::DailyNote>; |
| 788 |
} |
| 789 |
|
| 790 |
|
| 791 |
#[async_trait] |
| 792 |
pub trait MonthlyReviewRepository: Send + Sync { |
| 793 |
|
| 794 |
async fn list_goals(&self, user_id: UserId, month: &str) -> Result<Vec<crate::models::MonthlyGoal>>; |
| 795 |
|
| 796 |
|
| 797 |
async fn upsert_goal(&self, user_id: UserId, month: &str, text: &str, position: i32) -> Result<crate::models::MonthlyGoal>; |
| 798 |
|
| 799 |
|
| 800 |
async fn update_goal_status(&self, id: crate::MonthlyGoalId, user_id: UserId, status: &crate::models::MonthlyGoalStatus) -> Result<Option<crate::models::MonthlyGoal>>; |
| 801 |
|
| 802 |
|
| 803 |
async fn delete_goal(&self, id: crate::MonthlyGoalId, user_id: UserId) -> Result<bool>; |
| 804 |
|
| 805 |
|
| 806 |
async fn get_reflection(&self, user_id: UserId, month: &str) -> Result<Option<crate::models::MonthlyReflection>>; |
| 807 |
|
| 808 |
|
| 809 |
async fn upsert_reflection(&self, user_id: UserId, month: &str, highlight: &str, change: &str) -> Result<crate::models::MonthlyReflection>; |
| 810 |
} |
| 811 |
|
| 812 |
|
| 813 |
#[async_trait] |
| 814 |
pub trait MilestoneRepository: Send + Sync { |
| 815 |
|
| 816 |
async fn list_by_project(&self, project_id: ProjectId, user_id: UserId) -> Result<Vec<crate::models::Milestone>>; |
| 817 |
|
| 818 |
|
| 819 |
async fn get_by_id(&self, id: MilestoneId, user_id: UserId) -> Result<Option<crate::models::Milestone>>; |
| 820 |
|
| 821 |
|
| 822 |
async fn create(&self, user_id: UserId, milestone: crate::models::NewMilestone) -> Result<crate::models::Milestone>; |
| 823 |
|
| 824 |
|
| 825 |
async fn update( |
| 826 |
&self, |
| 827 |
id: MilestoneId, |
| 828 |
user_id: UserId, |
| 829 |
name: &str, |
| 830 |
description: &str, |
| 831 |
target_date: Option<NaiveDate>, |
| 832 |
status: &crate::models::MilestoneStatus, |
| 833 |
) -> Result<Option<crate::models::Milestone>>; |
| 834 |
|
| 835 |
|
| 836 |
async fn delete(&self, id: MilestoneId, user_id: UserId) -> Result<bool>; |
| 837 |
|
| 838 |
|
| 839 |
async fn reorder(&self, project_id: ProjectId, user_id: UserId, milestone_ids: &[MilestoneId]) -> Result<()>; |
| 840 |
} |
| 841 |
|
| 842 |
|
| 843 |
#[async_trait] |
| 844 |
pub trait BackupSettingsRepository: Send + Sync { |
| 845 |
|
| 846 |
async fn get(&self, user_id: UserId) -> Result<Option<crate::models::BackupSettings>>; |
| 847 |
|
| 848 |
|
| 849 |
async fn upsert( |
| 850 |
&self, |
| 851 |
user_id: UserId, |
| 852 |
settings: crate::models::NewBackupSettings, |
| 853 |
) -> Result<crate::models::BackupSettings>; |
| 854 |
|
| 855 |
|
| 856 |
async fn update_last_backup_at(&self, user_id: UserId, timestamp: DateTime<Utc>) -> Result<()>; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
#[async_trait] |
| 864 |
pub trait ContactRepository: Send + Sync { |
| 865 |
|
| 866 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<Contact>>; |
| 867 |
|
| 868 |
|
| 869 |
async fn get_by_id(&self, id: ContactId, user_id: UserId) -> Result<Option<Contact>>; |
| 870 |
|
| 871 |
|
| 872 |
async fn create(&self, user_id: UserId, contact: NewContact) -> Result<Contact>; |
| 873 |
|
| 874 |
|
| 875 |
async fn update(&self, id: ContactId, user_id: UserId, contact: UpdateContact) -> Result<Option<Contact>>; |
| 876 |
|
| 877 |
|
| 878 |
async fn delete(&self, id: ContactId, user_id: UserId) -> Result<bool>; |
| 879 |
|
| 880 |
|
| 881 |
async fn delete_many(&self, ids: &[ContactId], user_id: UserId) -> Result<u64>; |
| 882 |
|
| 883 |
|
| 884 |
async fn tag_many(&self, ids: &[ContactId], user_id: UserId, tag: &str) -> Result<u64>; |
| 885 |
|
| 886 |
|
| 887 |
async fn list_by_tag(&self, user_id: UserId, tag: &str) -> Result<Vec<Contact>>; |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
async fn list_filtered(&self, user_id: UserId, search: Option<&str>, tag: Option<&str>, include_implicit: bool) -> Result<Vec<Contact>>; |
| 892 |
|
| 893 |
|
| 894 |
async fn find_by_email(&self, user_id: UserId, email: &str) -> Result<Option<Contact>>; |
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
async fn find_emails_in_contacts(&self, user_id: UserId, addresses: &[&str]) -> Result<HashSet<String>>; |
| 899 |
|
| 900 |
|
| 901 |
async fn promote_contact(&self, id: ContactId, user_id: UserId) -> Result<Option<Contact>>; |
| 902 |
|
| 903 |
|
| 904 |
async fn find_by_external_id(&self, source: &str, ext_id: &str, user_id: UserId) -> Result<Option<Contact>>; |
| 905 |
|
| 906 |
|
| 907 |
async fn add_email(&self, contact_id: ContactId, user_id: UserId, email: NewContactEmail) -> Result<ContactEmail>; |
| 908 |
|
| 909 |
|
| 910 |
async fn remove_email(&self, email_id: ContactEmailId, user_id: UserId) -> Result<bool>; |
| 911 |
|
| 912 |
|
| 913 |
async fn add_phone(&self, contact_id: ContactId, user_id: UserId, phone: NewContactPhone) -> Result<ContactPhone>; |
| 914 |
|
| 915 |
|
| 916 |
async fn remove_phone(&self, phone_id: ContactPhoneId, user_id: UserId) -> Result<bool>; |
| 917 |
|
| 918 |
|
| 919 |
async fn add_social_handle(&self, contact_id: ContactId, user_id: UserId, handle: NewSocialHandle) -> Result<SocialHandle>; |
| 920 |
|
| 921 |
|
| 922 |
async fn remove_social_handle(&self, handle_id: SocialHandleId, user_id: UserId) -> Result<bool>; |
| 923 |
|
| 924 |
|
| 925 |
async fn add_custom_field(&self, contact_id: ContactId, user_id: UserId, field: NewContactCustomField) -> Result<ContactCustomField>; |
| 926 |
|
| 927 |
|
| 928 |
async fn remove_custom_field(&self, field_id: CustomFieldId, user_id: UserId) -> Result<bool>; |
| 929 |
|
| 930 |
|
| 931 |
async fn update_email(&self, email_id: ContactEmailId, user_id: UserId, email: NewContactEmail) -> Result<Option<ContactEmail>>; |
| 932 |
|
| 933 |
|
| 934 |
async fn update_phone(&self, phone_id: ContactPhoneId, user_id: UserId, phone: NewContactPhone) -> Result<Option<ContactPhone>>; |
| 935 |
|
| 936 |
|
| 937 |
async fn update_social_handle(&self, handle_id: SocialHandleId, user_id: UserId, handle: NewSocialHandle) -> Result<Option<SocialHandle>>; |
| 938 |
|
| 939 |
|
| 940 |
async fn update_custom_field(&self, field_id: CustomFieldId, user_id: UserId, field: NewContactCustomField) -> Result<Option<ContactCustomField>>; |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
#[async_trait] |
| 945 |
pub trait AttachmentRepository: Send + Sync { |
| 946 |
|
| 947 |
async fn create(&self, user_id: UserId, attachment: NewAttachment) -> Result<Attachment>; |
| 948 |
|
| 949 |
|
| 950 |
async fn list_for_task(&self, task_id: TaskId, user_id: UserId) -> Result<Vec<Attachment>>; |
| 951 |
|
| 952 |
|
| 953 |
async fn list_for_project(&self, project_id: ProjectId, user_id: UserId) -> Result<Vec<Attachment>>; |
| 954 |
|
| 955 |
|
| 956 |
async fn get_by_id(&self, id: AttachmentId, user_id: UserId) -> Result<Option<Attachment>>; |
| 957 |
|
| 958 |
|
| 959 |
async fn delete(&self, id: AttachmentId, user_id: UserId) -> Result<bool>; |
| 960 |
|
| 961 |
|
| 962 |
async fn list_by_blob_hash(&self, blob_hash: &str, user_id: UserId) -> Result<Vec<Attachment>>; |
| 963 |
|
| 964 |
|
| 965 |
async fn list_all_blob_hashes(&self, user_id: UserId) -> Result<Vec<String>>; |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
#[async_trait] |
| 970 |
pub trait SyncAccountRepository: Send + Sync { |
| 971 |
|
| 972 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<crate::models::SyncAccount>>; |
| 973 |
|
| 974 |
|
| 975 |
async fn get_by_id(&self, id: SyncAccountId, user_id: UserId) -> Result<Option<crate::models::SyncAccount>>; |
| 976 |
|
| 977 |
|
| 978 |
async fn create(&self, user_id: UserId, provider: &str, account_name: &str, email: Option<&str>) -> Result<crate::models::SyncAccount>; |
| 979 |
|
| 980 |
|
| 981 |
async fn update(&self, id: SyncAccountId, user_id: UserId, account_name: &str, sync_calendars: bool, sync_contacts: bool, enabled: bool) -> Result<Option<crate::models::SyncAccount>>; |
| 982 |
|
| 983 |
|
| 984 |
async fn delete(&self, id: SyncAccountId, user_id: UserId) -> Result<bool>; |
| 985 |
} |
| 986 |
|