This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
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<u32>,
|
||||
},
|
||||
Monthly {
|
||||
days: Vec<u32>,
|
||||
#[serde(default = "default_true")]
|
||||
clamp_to_last_day: bool,
|
||||
},
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateTask {
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub notes: Option<String>,
|
||||
pub section: Section,
|
||||
pub priority: Priority,
|
||||
pub scheduled_date: String,
|
||||
#[serde(default)]
|
||||
pub reminder_time: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RescheduleTask {
|
||||
pub scheduled_date: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
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 scheduled_date: String,
|
||||
pub reminder_time: Option<String>,
|
||||
pub status: String,
|
||||
pub completed_at: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateRoutine {
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub notes: Option<String>,
|
||||
pub section: Section,
|
||||
pub priority: Priority,
|
||||
pub schedule: Schedule,
|
||||
#[serde(default)]
|
||||
pub reminder_time: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Routine {
|
||||
pub id: i64,
|
||||
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)]
|
||||
pub struct DueNotification {
|
||||
pub task_id: i64,
|
||||
pub 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,
|
||||
}
|
||||
Reference in New Issue
Block a user