backbone-bucket 0.2.0

Bucket Bounded Context: File Storage Module for Backbone Framework
Documentation
//! Repository trait for FileShare aggregate
//!
//! Generated by metaphor-schema. Do not edit manually.
//!
//! This trait defines the repository contract for the FileShare aggregate.
//! Implementation is in the infrastructure layer.

use async_trait::async_trait;
use anyhow::Result;
use uuid::Uuid;

use crate::domain::entity::{FileShare, SharePermission, ShareStatus, ShareType};

/// Pagination parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct FileSharePaginationParams {
    pub page: u32,
    pub per_page: u32,
}

impl FileSharePaginationParams {
    pub fn new(page: u32, per_page: u32) -> Self {
        Self { page, per_page }
    }

    pub fn offset(&self) -> u64 {
        ((self.page.saturating_sub(1)) * self.per_page) as u64
    }

    pub fn limit(&self) -> u64 {
        self.per_page as u64
    }
}

/// Paginated result for list queries
#[derive(Debug, Clone)]
pub struct FileSharePaginatedResult {
    pub data: Vec<FileShare>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct FileShareFilter {
    pub file_id: Option<Uuid>,
    pub owner_id: Option<Uuid>,
    pub token: Option<String>,
    pub share_type: Option<ShareType>,
    pub permission: Option<SharePermission>,
    pub password_hash: Option<String>,
    pub status: Option<ShareStatus>,
    pub revoked_by: Option<Uuid>,
    pub message: Option<String>,
}

impl FileShareFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.file_id.is_some() || self.owner_id.is_some() || self.token.is_some() || self.share_type.is_some() || self.permission.is_some() || self.password_hash.is_some() || self.status.is_some() || self.revoked_by.is_some() || self.message.is_some()
    }
}

/// Repository trait for FileShare aggregate
///
/// This trait defines the persistence contract for FileShare entities.
/// Implementations should be in the infrastructure layer.
#[async_trait]
pub trait FileShareRepository: Send + Sync {

    // =========================================================================
    // Core CRUD Operations
    // =========================================================================

    /// Save a new file_share entity
    async fn save(&self, entity: &FileShare) -> Result<FileShare>;

    /// Find file_share by ID
    async fn find_by_id(&self, id: &str) -> Result<Option<FileShare>>;

    /// Find all file_share entities
    async fn find_all(&self) -> Result<Vec<FileShare>>;

    /// Update file_share by ID
    async fn update(&self, id: &str, entity: &FileShare) -> Result<Option<FileShare>>;

    /// Delete file_share by ID
    async fn delete(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Pagination
    // =========================================================================

    /// List file_share with pagination
    async fn list(&self, params: FileSharePaginationParams) -> Result<FileSharePaginatedResult>;

    /// List file_share with pagination and filters
    async fn list_with_filters(&self, params: FileSharePaginationParams, filters: FileShareFilter) -> Result<FileSharePaginatedResult>;

    /// Count all file_share entities
    async fn count(&self) -> Result<u64>;

    /// Count file_share entities matching filters
    async fn count_with_filters(&self, filters: FileShareFilter) -> Result<u64>;

    /// Check if file_share exists by ID
    async fn exists(&self, id: &str) -> Result<bool>;

    // =========================================================================
    // Soft Delete Operations
    // =========================================================================

    /// Soft delete file_share by ID
    async fn soft_delete(&self, id: &str) -> Result<bool>;

    /// Restore soft-deleted file_share by ID
    async fn restore(&self, id: &str) -> Result<Option<FileShare>>;

    /// List soft-deleted file_share entities
    async fn list_deleted(&self, params: FileSharePaginationParams) -> Result<FileSharePaginatedResult>;

    /// Empty trash (permanently delete all soft-deleted entities)
    async fn empty_trash(&self) -> Result<u64>;

    // =========================================================================
    // Query by Unique Fields
    // =========================================================================

    /// Find file_share by token
    async fn find_by_token(&self, token: &str) -> Result<Option<FileShare>>;

    // =========================================================================
    // Existence Checks by Unique Fields
    // =========================================================================

    /// Check if file_share exists by token
    async fn exists_by_token(&self, token: &str) -> Result<bool>;

    // =========================================================================
    // Bulk Operations
    // =========================================================================

    /// Bulk save file_share entities
    async fn bulk_save(&self, entities: &[FileShare]) -> Result<Vec<FileShare>>;

    /// Bulk delete by IDs
    async fn bulk_delete(&self, ids: &[&str]) -> Result<u64>;
}