| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
use chrono::{DateTime, Utc}; |
| 8 |
use serde::{Deserialize, Serialize}; |
| 9 |
use strum_macros::EnumString; |
| 10 |
use crate::id_types::{SavedViewId, UserId, ProjectId}; |
| 11 |
|
| 12 |
use super::shared::{DbValue, ParseableEnum, SortDirection}; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, EnumString)] |
| 18 |
#[serde(rename_all = "lowercase")] |
| 19 |
pub enum ViewType { |
| 20 |
|
| 21 |
#[default] |
| 22 |
#[strum(serialize = "tasks")] |
| 23 |
Tasks, |
| 24 |
|
| 25 |
#[strum(serialize = "emails")] |
| 26 |
Emails, |
| 27 |
|
| 28 |
#[strum(serialize = "events")] |
| 29 |
Events, |
| 30 |
} |
| 31 |
|
| 32 |
impl ViewType { |
| 33 |
|
| 34 |
pub fn as_str(&self) -> &'static str { |
| 35 |
match self { |
| 36 |
ViewType::Tasks => "Tasks", |
| 37 |
ViewType::Emails => "Emails", |
| 38 |
ViewType::Events => "Events", |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
impl ParseableEnum for ViewType {} |
| 45 |
|
| 46 |
impl DbValue for ViewType { |
| 47 |
fn db_value(&self) -> &'static str { |
| 48 |
match self { |
| 49 |
ViewType::Tasks => "tasks", |
| 50 |
ViewType::Emails => "emails", |
| 51 |
ViewType::Events => "events", |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] |
| 58 |
#[serde(rename_all = "snake_case")] |
| 59 |
pub enum SortField { |
| 60 |
|
| 61 |
Urgency, |
| 62 |
|
| 63 |
Due, |
| 64 |
|
| 65 |
CreatedAt, |
| 66 |
|
| 67 |
Description, |
| 68 |
|
| 69 |
Priority, |
| 70 |
|
| 71 |
Project, |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
#[derive(Debug, Clone, Serialize, Deserialize, Default)] |
| 76 |
#[serde(rename_all = "camelCase")] |
| 77 |
pub struct ViewFilters { |
| 78 |
|
| 79 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 80 |
pub status: Option<Vec<crate::models::TaskStatus>>, |
| 81 |
|
| 82 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 83 |
pub project_id: Option<ProjectId>, |
| 84 |
|
| 85 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 86 |
pub tags: Option<Vec<String>>, |
| 87 |
|
| 88 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 89 |
pub priority: Option<Vec<crate::models::Priority>>, |
| 90 |
|
| 91 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 92 |
pub due_from: Option<DateTime<Utc>>, |
| 93 |
|
| 94 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 95 |
pub due_to: Option<DateTime<Utc>>, |
| 96 |
|
| 97 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 98 |
pub is_read: Option<bool>, |
| 99 |
|
| 100 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 101 |
pub is_archived: Option<bool>, |
| 102 |
|
| 103 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 104 |
pub is_snoozed: Option<bool>, |
| 105 |
|
| 106 |
#[serde(skip_serializing_if = "Option::is_none")] |
| 107 |
pub is_waiting: Option<bool>, |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 112 |
#[serde(rename_all = "camelCase")] |
| 113 |
pub struct SavedView { |
| 114 |
|
| 115 |
pub id: SavedViewId, |
| 116 |
|
| 117 |
#[serde(skip_serializing)] |
| 118 |
pub user_id: UserId, |
| 119 |
|
| 120 |
pub name: String, |
| 121 |
|
| 122 |
pub view_type: ViewType, |
| 123 |
|
| 124 |
pub filters: ViewFilters, |
| 125 |
|
| 126 |
pub sort_by: Option<SortField>, |
| 127 |
|
| 128 |
pub sort_order: SortDirection, |
| 129 |
|
| 130 |
pub is_pinned: bool, |
| 131 |
|
| 132 |
pub position: i32, |
| 133 |
|
| 134 |
pub created_at: DateTime<Utc>, |
| 135 |
|
| 136 |
pub updated_at: DateTime<Utc>, |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
#[derive(Debug, Clone, Serialize, Deserialize)] |
| 143 |
#[serde(rename_all = "camelCase")] |
| 144 |
pub struct NewSavedView { |
| 145 |
|
| 146 |
pub name: String, |
| 147 |
|
| 148 |
pub view_type: ViewType, |
| 149 |
|
| 150 |
pub filters: ViewFilters, |
| 151 |
|
| 152 |
pub sort_by: Option<SortField>, |
| 153 |
|
| 154 |
pub sort_order: Option<SortDirection>, |
| 155 |
|
| 156 |
pub is_pinned: Option<bool>, |
| 157 |
} |
| 158 |
|