This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Task {
|
||||
pub id: i64,
|
||||
pub routine_id: Option<i64>,
|
||||
pub title: String,
|
||||
pub notes: Option<String>,
|
||||
pub section: String,
|
||||
pub priority: String,
|
||||
pub reminder_time: Option<String>,
|
||||
pub status: String,
|
||||
pub completed_at: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct Routine {
|
||||
pub title: String,
|
||||
pub notes: Option<String>,
|
||||
pub section: String,
|
||||
pub priority: String,
|
||||
pub schedule: Schedule,
|
||||
pub reminder_time: Option<String>,
|
||||
pub enabled: 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 title: String,
|
||||
pub notes: Option<String>,
|
||||
pub section: String,
|
||||
pub priority: String,
|
||||
pub scheduled_date: String,
|
||||
pub reminder_time: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CreateRoutine {
|
||||
pub title: String,
|
||||
pub notes: 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,
|
||||
}
|
||||
|
||||
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(",")
|
||||
}
|
||||
Reference in New Issue
Block a user