Files
Oxicloud/src/application/ports/recent_ports.rs
T

56 lines
2.2 KiB
Rust
Raw Normal View History

2025-04-02 05:08:30 +02:00
use crate::application::dtos::recent_dto::RecentItemDto;
2026-02-14 01:29:34 +01:00
use crate::common::errors::Result;
use async_trait::async_trait;
2025-04-02 05:08:30 +02:00
/// Defines operations for managing user recent items
2025-04-02 05:08:30 +02:00
#[async_trait]
pub trait RecentItemsUseCase: Send + Sync {
/// Get all recent items for a user
2026-02-14 01:29:34 +01:00
async fn get_recent_items(
&self,
user_id: &str,
limit: Option<i32>,
) -> Result<Vec<RecentItemDto>>;
/// Record access to an item
2026-02-14 01:29:34 +01:00
async fn record_item_access(&self, user_id: &str, item_id: &str, item_type: &str)
-> Result<()>;
/// Remove an item from recents
2026-02-14 01:29:34 +01:00
async fn remove_from_recent(
&self,
user_id: &str,
item_id: &str,
item_type: &str,
) -> Result<bool>;
/// Clear the entire recent items list
2025-04-02 05:08:30 +02:00
async fn clear_recent_items(&self, user_id: &str) -> Result<()>;
}
// ─────────────────────────────────────────────────────
// Outbound port — persistence abstraction
// ─────────────────────────────────────────────────────
/// Secondary (outbound) port for recent items persistence.
///
/// Abstracts access to the `auth.user_recent_files` table so that
/// `RecentService` does not depend directly on `PgPool`.
#[async_trait]
pub trait RecentItemsRepositoryPort: Send + Sync + 'static {
/// Gets the latest recent items for a user (ordered by date desc).
async fn get_recent_items(&self, user_id: &str, limit: i32) -> Result<Vec<RecentItemDto>>;
/// Records/updates access to an item (upsert by user+item+type).
async fn upsert_access(&self, user_id: &str, item_id: &str, item_type: &str) -> Result<()>;
/// Removes an item from recents. Returns `true` if it existed.
async fn remove_item(&self, user_id: &str, item_id: &str, item_type: &str) -> Result<bool>;
/// Removes all recent items for a user.
async fn clear_all(&self, user_id: &str) -> Result<()>;
/// Removes items exceeding `max_items` (the oldest ones).
async fn prune(&self, user_id: &str, max_items: i32) -> Result<()>;
2026-02-14 01:29:34 +01:00
}