use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Task {
pub id: u32,
pub description: String,
pub completed: bool,
#[serde(with = "chrono::serde::ts_seconds")] pub created_at: DateTime<Utc>,
pub due_date: Option<NaiveDate>,
}
impl Task {
pub fn new(id: u32, description: String, due_date: Option<NaiveDate>) -> Self {
Task {
id,
description,
completed: false,
created_at: Utc::now(),
due_date,
}
}
pub fn mark_completion(&mut self, status: bool) {
self.completed = status;
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct TaskList {
pub tasks: Vec<Task>,
}
impl TaskList {
pub fn new() -> Self {
TaskList { tasks: Vec::new() }
}
}
impl Default for TaskList {
fn default() -> Self {
Self::new()
}
}