2025-03-28 12:38:48 +01:00
|
|
|
use crate::{
|
|
|
|
|
application::dtos::{
|
|
|
|
|
pagination::PaginatedResponseDto,
|
2026-02-14 01:29:34 +01:00
|
|
|
share_dto::{CreateShareDto, ShareDto, UpdateShareDto},
|
2025-03-28 12:38:48 +01:00
|
|
|
},
|
|
|
|
|
common::errors::DomainError,
|
|
|
|
|
domain::entities::share::ShareItemType,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub trait ShareUseCase: Send + Sync + 'static {
|
|
|
|
|
/// Create a new shared link for a file or folder
|
|
|
|
|
async fn create_shared_link(
|
|
|
|
|
&self,
|
|
|
|
|
user_id: &str,
|
|
|
|
|
dto: CreateShareDto,
|
|
|
|
|
) -> Result<ShareDto, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Get a shared link by its ID (ownership-verified)
|
2026-03-05 21:28:51 +01:00
|
|
|
async fn get_shared_link(&self, id: &str, requester_id: &str) -> Result<ShareDto, DomainError>;
|
2025-03-28 12:38:48 +01:00
|
|
|
|
|
|
|
|
/// Get a shared link by its token (for access by non-users)
|
|
|
|
|
async fn get_shared_link_by_token(&self, token: &str) -> Result<ShareDto, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Get all shared links for a specific item (ownership-verified)
|
2025-03-28 12:38:48 +01:00
|
|
|
async fn get_shared_links_for_item(
|
|
|
|
|
&self,
|
|
|
|
|
item_id: &str,
|
|
|
|
|
item_type: &ShareItemType,
|
2026-03-05 13:15:34 +01:00
|
|
|
requester_id: &str,
|
2025-03-28 12:38:48 +01:00
|
|
|
) -> Result<Vec<ShareDto>, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Update a shared link (ownership-verified)
|
2025-03-28 12:38:48 +01:00
|
|
|
async fn update_shared_link(
|
|
|
|
|
&self,
|
|
|
|
|
id: &str,
|
2026-03-05 13:15:34 +01:00
|
|
|
requester_id: &str,
|
2025-03-28 12:38:48 +01:00
|
|
|
dto: UpdateShareDto,
|
|
|
|
|
) -> Result<ShareDto, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Delete a shared link (ownership-verified)
|
|
|
|
|
async fn delete_shared_link(&self, id: &str, requester_id: &str) -> Result<(), DomainError>;
|
2025-03-28 12:38:48 +01:00
|
|
|
|
|
|
|
|
/// Get all shared links created by a specific user
|
|
|
|
|
async fn get_user_shared_links(
|
|
|
|
|
&self,
|
|
|
|
|
user_id: &str,
|
|
|
|
|
page: usize,
|
|
|
|
|
per_page: usize,
|
|
|
|
|
) -> Result<PaginatedResponseDto<ShareDto>, DomainError>;
|
|
|
|
|
|
2026-03-05 16:09:37 +01:00
|
|
|
/// Verify a password for a password-protected shared link.
|
|
|
|
|
/// On success, returns the full share metadata (`ShareDto`).
|
|
|
|
|
/// On failure (wrong password), returns `AccessDenied`.
|
2025-03-28 12:38:48 +01:00
|
|
|
async fn verify_shared_link_password(
|
|
|
|
|
&self,
|
|
|
|
|
token: &str,
|
|
|
|
|
password: &str,
|
2026-03-05 16:09:37 +01:00
|
|
|
) -> Result<ShareDto, DomainError>;
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2025-03-28 12:38:48 +01:00
|
|
|
/// Register an access to a shared link
|
|
|
|
|
async fn register_shared_link_access(&self, token: &str) -> Result<(), DomainError>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait ShareStoragePort: Send + Sync + 'static {
|
2026-02-14 01:29:34 +01:00
|
|
|
async fn save_share(
|
|
|
|
|
&self,
|
|
|
|
|
share: &crate::domain::entities::share::Share,
|
|
|
|
|
) -> Result<crate::domain::entities::share::Share, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
async fn find_share_by_token(
|
2026-02-14 01:29:34 +01:00
|
|
|
&self,
|
2026-03-05 13:15:34 +01:00
|
|
|
token: &str,
|
2026-02-14 01:29:34 +01:00
|
|
|
) -> Result<crate::domain::entities::share::Share, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Find a share by ID only if it belongs to the given user.
|
|
|
|
|
/// Returns `NotFound` if the share doesn't exist OR belongs to another user
|
|
|
|
|
/// (prevents share-ID enumeration).
|
|
|
|
|
async fn find_share_by_id_for_user(
|
2026-02-14 01:29:34 +01:00
|
|
|
&self,
|
2026-03-05 13:15:34 +01:00
|
|
|
id: &str,
|
|
|
|
|
user_id: &str,
|
2026-02-14 01:29:34 +01:00
|
|
|
) -> Result<crate::domain::entities::share::Share, DomainError>;
|
|
|
|
|
|
2026-03-05 13:15:34 +01:00
|
|
|
/// Delete a share only if it belongs to the given user.
|
|
|
|
|
async fn delete_share_for_user(&self, id: &str, user_id: &str) -> Result<(), DomainError>;
|
|
|
|
|
|
|
|
|
|
/// Find shares for a specific item that belong to the given user.
|
|
|
|
|
async fn find_shares_by_item_for_user(
|
2026-02-14 01:29:34 +01:00
|
|
|
&self,
|
|
|
|
|
item_id: &str,
|
|
|
|
|
item_type: &ShareItemType,
|
2026-03-05 13:15:34 +01:00
|
|
|
user_id: &str,
|
2026-02-14 01:29:34 +01:00
|
|
|
) -> Result<Vec<crate::domain::entities::share::Share>, DomainError>;
|
|
|
|
|
|
|
|
|
|
async fn update_share(
|
|
|
|
|
&self,
|
|
|
|
|
share: &crate::domain::entities::share::Share,
|
|
|
|
|
) -> Result<crate::domain::entities::share::Share, DomainError>;
|
|
|
|
|
|
|
|
|
|
async fn find_shares_by_user(
|
|
|
|
|
&self,
|
|
|
|
|
user_id: &str,
|
|
|
|
|
offset: usize,
|
|
|
|
|
limit: usize,
|
|
|
|
|
) -> Result<(Vec<crate::domain::entities::share::Share>, usize), DomainError>;
|
2025-03-28 12:38:48 +01:00
|
|
|
}
|