backbone-bucket 0.3.1

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

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

use crate::domain::entity::{FileComment, CommentStatus};

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

impl FileCommentPaginationParams {
    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 FileCommentPaginatedResult {
    pub data: Vec<FileComment>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct FileCommentFilter {
    pub file_id: Option<Uuid>,
    pub user_id: Option<Uuid>,
    pub parent_id: Option<Uuid>,
    pub content: Option<String>,
    pub resolved: Option<bool>,
    pub resolved_by: Option<Uuid>,
    pub status: Option<CommentStatus>,
}

impl FileCommentFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.file_id.is_some() || self.user_id.is_some() || self.parent_id.is_some() || self.content.is_some() || self.resolved.is_some() || self.resolved_by.is_some() || self.status.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List file_comment with pagination
    async fn list(&self, params: FileCommentPaginationParams) -> Result<FileCommentPaginatedResult>;

    /// List file_comment with pagination and filters
    async fn list_with_filters(&self, params: FileCommentPaginationParams, filters: FileCommentFilter) -> Result<FileCommentPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted file_comment entities
    async fn list_deleted(&self, params: FileCommentPaginationParams) -> Result<FileCommentPaginatedResult>;

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

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

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

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