use async_trait::async_trait;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::types::DatabaseError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Notebook {
pub id: Uuid,
pub owner_id: Uuid,
pub name: String,
pub cells: serde_json::Value,
pub deletable: bool,
pub created_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Default)]
pub struct NotebookUpdatePatch {
pub name: Option<String>,
pub cells: Option<serde_json::Value>,
}
#[async_trait]
pub trait NotebookDb: Send + Sync + 'static {
async fn list_by_owner(&self, owner_id: Uuid) -> Result<Vec<Notebook>, DatabaseError>;
async fn create(
&self,
owner_id: Uuid,
name: String,
cells: serde_json::Value,
deletable: bool,
) -> Result<Notebook, DatabaseError>;
async fn create_seeded(
&self,
id: Uuid,
owner_id: Uuid,
name: String,
cells: serde_json::Value,
deletable: bool,
) -> Result<Notebook, DatabaseError>;
async fn get_by_id_and_owner(
&self,
id: Uuid,
owner_id: Uuid,
) -> Result<Option<Notebook>, DatabaseError>;
async fn update(
&self,
id: Uuid,
owner_id: Uuid,
patch: NotebookUpdatePatch,
) -> Result<Option<Notebook>, DatabaseError>;
async fn delete(&self, id: Uuid, owner_id: Uuid) -> Result<bool, DatabaseError>;
}