mabel/src/content/collection.rs

43 lines
992 B
Rust

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use uuid::Uuid;
use super::Error;
pub const DEFAULT_COLLECTIONS: [(&str, &str); 2] = [("blog", "Blog"), ("pages", "Pages")];
#[derive(Debug, Deserialize, Serialize, FromRow)]
pub struct Collection {
/// Collection ID
pub id: Uuid,
/// Site ID
pub site: Uuid,
/// Collection URL name
pub slug: String,
/// Collection display name
pub name: String,
/// Collection parent (eg. blog categories have blog as parent)
pub parent: Option<Uuid>,
}
#[derive(Debug, Serialize)]
pub struct CollectionData {
pub id: Uuid,
pub slug: String,
pub name: String,
pub parent: Option<Uuid>,
}
#[async_trait]
pub trait CollectionRepository {
async fn list_collections(&self, site: &Uuid) -> Result<Vec<CollectionData>, Error>;
/// Create default collections for a site
async fn create_default_collections(&self, site: &Uuid) -> Result<(), Error>;
}