use async_trait::async_trait;
use std::path::Path;
use crate::error::StoreError;
use crate::filters::Filters;
use crate::id::{Identifiable, ItemId};
use super::metadata::ItemMetadata;
pub trait Item: Identifiable + Send + Sync + Sized {
type Metadata: ItemMetadata;
const STORAGE_FOLDER: &'static str;
fn title(&self) -> &str;
fn description(&self) -> &str;
fn metadata(&self) -> &Self::Metadata;
fn metadata_mut(&mut self) -> &mut Self::Metadata;
fn content_filename(&self) -> String;
fn metadata_filename(&self) -> Option<String>;
}
#[derive(Debug, Clone)]
pub struct ItemWithProject<T: Item> {
pub item: T,
pub project_path: String,
pub project_name: String,
}
#[async_trait]
pub trait ItemCrud: Item {
type CreateOptions;
type CreateResult;
type UpdateOptions;
type UpdateResult;
async fn create(
project_path: &Path,
options: Self::CreateOptions,
) -> Result<Self::CreateResult, StoreError>;
async fn get(project_path: &Path, id: &ItemId) -> Result<Self, StoreError>;
async fn list(project_path: &Path, filters: Filters) -> Result<Vec<Self>, StoreError>;
async fn update(
project_path: &Path,
id: &ItemId,
options: Self::UpdateOptions,
) -> Result<Self::UpdateResult, StoreError>;
async fn delete(project_path: &Path, id: &ItemId) -> Result<(), StoreError>;
}