165 lines
4.0 KiB
Rust
165 lines
4.0 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct Task {
|
|
pub id: i64,
|
|
pub routine_id: Option<i64>,
|
|
pub public_title: String,
|
|
pub encrypted_payload: Option<String>,
|
|
pub encryption_version: Option<i16>,
|
|
pub content_id: Option<String>,
|
|
pub section: String,
|
|
pub priority: String,
|
|
pub scheduled_date: String,
|
|
pub reminder_time: Option<String>,
|
|
pub status: String,
|
|
pub completed_at: Option<i64>,
|
|
#[serde(skip)]
|
|
pub private_title: Option<String>,
|
|
#[serde(skip)]
|
|
pub private_notes: Option<String>,
|
|
#[serde(skip)]
|
|
pub decryption_failed: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct Routine {
|
|
pub public_title: String,
|
|
pub encrypted_payload: Option<String>,
|
|
pub encryption_version: Option<i16>,
|
|
pub content_id: Option<String>,
|
|
pub section: String,
|
|
pub priority: String,
|
|
pub schedule: Schedule,
|
|
pub reminder_time: Option<String>,
|
|
pub enabled: bool,
|
|
#[serde(skip)]
|
|
pub private_title: Option<String>,
|
|
#[serde(skip)]
|
|
pub private_notes: Option<String>,
|
|
#[serde(skip)]
|
|
pub decryption_failed: bool,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
#[serde(tag = "kind", rename_all = "snake_case")]
|
|
pub enum Schedule {
|
|
Daily,
|
|
Weekly {
|
|
weekdays: Vec<u32>,
|
|
},
|
|
Monthly {
|
|
days: Vec<u32>,
|
|
clamp_to_last_day: bool,
|
|
},
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct CreateTask {
|
|
pub public_title: String,
|
|
pub encrypted_payload: Option<String>,
|
|
pub encryption_version: Option<i16>,
|
|
pub content_id: Option<String>,
|
|
pub section: String,
|
|
pub priority: String,
|
|
pub scheduled_date: String,
|
|
pub reminder_time: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct CreateRoutine {
|
|
pub public_title: String,
|
|
pub encrypted_payload: Option<String>,
|
|
pub encryption_version: Option<i16>,
|
|
pub content_id: Option<String>,
|
|
pub section: String,
|
|
pub priority: String,
|
|
pub schedule: Schedule,
|
|
pub reminder_time: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct RescheduleTask {
|
|
pub scheduled_date: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct EncryptionDevice {
|
|
pub id: i64,
|
|
pub name: String,
|
|
pub age_recipient: String,
|
|
pub status: String,
|
|
pub created_at: i64,
|
|
pub revoked_at: Option<i64>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct EncryptionRecipient {
|
|
pub age_recipient: String,
|
|
}
|
|
|
|
#[derive(Debug, Serialize)]
|
|
pub struct CreateEncryptionDevice {
|
|
pub name: String,
|
|
pub age_recipient: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize)]
|
|
pub struct PrivatePayload {
|
|
pub version: u8,
|
|
pub content_id: String,
|
|
#[serde(default)]
|
|
pub private_title: Option<String>,
|
|
#[serde(default)]
|
|
pub notes: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct EncryptedFields {
|
|
pub encrypted_payload: Option<String>,
|
|
pub encryption_version: Option<i16>,
|
|
pub content_id: Option<String>,
|
|
}
|
|
|
|
impl Task {
|
|
pub fn visible_title(&self) -> &str {
|
|
self.private_title.as_deref().unwrap_or(&self.public_title)
|
|
}
|
|
|
|
pub fn visible_notes(&self) -> Option<&str> {
|
|
self.private_notes.as_deref()
|
|
}
|
|
}
|
|
|
|
impl Routine {
|
|
pub fn visible_title(&self) -> &str {
|
|
self.private_title.as_deref().unwrap_or(&self.public_title)
|
|
}
|
|
|
|
pub fn visible_notes(&self) -> Option<&str> {
|
|
self.private_notes.as_deref()
|
|
}
|
|
}
|
|
|
|
pub fn schedule_label(schedule: &Schedule) -> String {
|
|
match schedule {
|
|
Schedule::Daily => "daily".to_owned(),
|
|
Schedule::Weekly { weekdays } => format!("weekly [{}]", join_numbers(weekdays)),
|
|
Schedule::Monthly {
|
|
days,
|
|
clamp_to_last_day,
|
|
} => {
|
|
let suffix = if *clamp_to_last_day { ", clamp" } else { "" };
|
|
format!("monthly [{}{suffix}]", join_numbers(days))
|
|
}
|
|
}
|
|
}
|
|
|
|
fn join_numbers(numbers: &[u32]) -> String {
|
|
numbers
|
|
.iter()
|
|
.map(u32::to_string)
|
|
.collect::<Vec<_>>()
|
|
.join(",")
|
|
}
|