Menu
Public repository / 9d3745320062c407696e8551819bba37d75fb0cf
AkurAI-Notes / crates/notes-core/src/entities/notebook.rs
Latest change 3f3c3218239131fdc60fb9196283c9a0162898a9 - E04: notes-core entities + CRUD handlers + collections schema + seed data by Claude Code
use akurai_json::Value;
pub struct Notebook {
pub id: i64,
pub name: String,
pub description: String,
pub owner_sub: String,
pub color: String,
pub created_at: i64,
}
impl Notebook {
pub fn from_json(v: &Value) -> Option<Self> {
Some(Self {
id: v.get("id")?.as_i64()?,
name: v.get("name")?.as_str()?.to_string(),
description: v.get("description")?.as_str().unwrap_or("").to_string(),
owner_sub: v.get("ownerSub")?.as_str()?.to_string(),
color: v.get("color")?.as_str().unwrap_or("#5b8cff").to_string(),
created_at: v.get("createdAt")?.as_i64()?,
})
}
pub fn to_json(&self) -> Value {
Value::Object(vec![
("id".into(), Value::Int(self.id)),
("name".into(), Value::Str(self.name.clone())),
("description".into(), Value::Str(self.description.clone())),
("ownerSub".into(), Value::Str(self.owner_sub.clone())),
("color".into(), Value::Str(self.color.clone())),
("createdAt".into(), Value::Int(self.created_at)),
])
}
}