use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum Section { Morning, Work, Evening, } impl Section { pub fn as_str(&self) -> &'static str { match self { Self::Morning => "morning", Self::Work => "work", Self::Evening => "evening", } } } #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum Priority { Must, Should, Optional, } impl Priority { pub fn as_str(&self) -> &'static str { match self { Self::Must => "must", Self::Should => "should", Self::Optional => "optional", } } } #[derive(Debug, Clone, Deserialize, Serialize)] #[serde(tag = "kind", rename_all = "snake_case")] pub enum Schedule { Daily, Weekly { /// ISO weekday numbers: Monday = 1, Sunday = 7. weekdays: Vec, }, Monthly { days: Vec, #[serde(default = "default_true")] clamp_to_last_day: bool, }, } fn default_true() -> bool { true } #[derive(Debug, Deserialize)] pub struct CreateTask { pub public_title: String, #[serde(default)] pub encrypted_payload: Option, #[serde(default)] pub encryption_version: Option, #[serde(default)] pub content_id: Option, pub section: Section, pub priority: Priority, pub scheduled_date: String, #[serde(default)] pub reminder_time: Option, } #[derive(Debug, Deserialize)] pub struct RescheduleTask { pub scheduled_date: String, } #[derive(Debug, Clone, Serialize)] pub struct Task { pub id: i64, pub routine_id: Option, pub public_title: String, pub encrypted_payload: Option, pub encryption_version: Option, pub content_id: Option, pub section: String, pub priority: String, pub scheduled_date: String, pub reminder_time: Option, pub status: String, pub completed_at: Option, } #[derive(Debug, Deserialize)] pub struct CreateRoutine { pub public_title: String, #[serde(default)] pub encrypted_payload: Option, #[serde(default)] pub encryption_version: Option, #[serde(default)] pub content_id: Option, pub section: Section, pub priority: Priority, pub schedule: Schedule, #[serde(default)] pub reminder_time: Option, } #[derive(Debug, Clone, Serialize)] pub struct Routine { pub id: i64, pub public_title: String, pub encrypted_payload: Option, pub encryption_version: Option, pub content_id: Option, pub section: String, pub priority: String, pub schedule: Schedule, pub reminder_time: Option, pub enabled: bool, } #[derive(Debug, Clone)] pub struct DueNotification { pub task_id: i64, pub public_title: String, pub section: String, pub priority: String, } #[derive(Debug, Serialize)] pub struct IdResponse { pub id: i64, } #[derive(Debug, Serialize)] pub struct StatusResponse { pub status: &'static str, } #[derive(Debug, Serialize)] pub struct ErrorResponse<'a> { pub error: &'a str, }