backbone-bucket 0.3.1

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

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

use crate::domain::entity::{AccessLog, AccessAction};

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

impl AccessLogPaginationParams {
    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 AccessLogPaginatedResult {
    pub data: Vec<AccessLog>,
    pub total: u64,
    pub page: u32,
    pub per_page: u32,
}

/// Filter parameters for list queries
#[derive(Debug, Clone, Default)]
pub struct AccessLogFilter {
    pub file_id: Option<Uuid>,
    pub bucket_id: Option<Uuid>,
    pub action: Option<AccessAction>,
    pub user_id: Option<Uuid>,
    pub share_id: Option<Uuid>,
    pub is_owner: Option<bool>,
    pub is_shared: Option<bool>,
    pub is_public: Option<bool>,
    pub ip_address: Option<String>,
    pub user_agent: Option<String>,
    pub referer: Option<String>,
    pub country_code: Option<String>,
    pub city: Option<String>,
    pub bytes_transferred: Option<i64>,
    pub duration_ms: Option<i32>,
    pub success: Option<bool>,
    pub error_message: Option<String>,
}

impl AccessLogFilter {
    /// Check if any filter is set
    pub fn has_filters(&self) -> bool {
        self.file_id.is_some() || self.bucket_id.is_some() || self.action.is_some() || self.user_id.is_some() || self.share_id.is_some() || self.is_owner.is_some() || self.is_shared.is_some() || self.is_public.is_some() || self.ip_address.is_some() || self.user_agent.is_some() || self.referer.is_some() || self.country_code.is_some() || self.city.is_some() || self.bytes_transferred.is_some() || self.duration_ms.is_some() || self.success.is_some() || self.error_message.is_some()
    }
}

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

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

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

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

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

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

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

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

    /// List access_log with pagination
    async fn list(&self, params: AccessLogPaginationParams) -> Result<AccessLogPaginatedResult>;

    /// List access_log with pagination and filters
    async fn list_with_filters(&self, params: AccessLogPaginationParams, filters: AccessLogFilter) -> Result<AccessLogPaginatedResult>;

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

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

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

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

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

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

    /// List soft-deleted access_log entities
    async fn list_deleted(&self, params: AccessLogPaginationParams) -> Result<AccessLogPaginatedResult>;

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

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

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

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