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