2025-03-18 22:14:29 +08:00
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
use database::{collections::fetch_collection, enums::AssetPermissionRole};
|
2025-03-12 02:16:28 +08:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
use crate::collections::types::{CollectionState, GetCollectionRequest};
|
|
|
|
|
|
|
|
/// Handler for getting a single collection by ID
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
/// * `user_id` - The ID of the user requesting the collection
|
|
|
|
/// * `req` - The request containing the collection ID
|
|
|
|
///
|
|
|
|
/// # Returns
|
|
|
|
/// * `Result<CollectionState>` - The collection state if found and accessible
|
|
|
|
pub async fn get_collection_handler(
|
|
|
|
user_id: &Uuid,
|
|
|
|
req: GetCollectionRequest,
|
|
|
|
) -> Result<CollectionState> {
|
|
|
|
// Reuse the existing collection_utils function
|
2025-03-18 22:14:29 +08:00
|
|
|
let collection = match fetch_collection(&req.id).await? {
|
|
|
|
Some(collection) => collection,
|
|
|
|
None => return Err(anyhow!("Collection not found")),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(CollectionState {
|
|
|
|
collection,
|
|
|
|
assets: None,
|
|
|
|
permission: AssetPermissionRole::Owner,
|
|
|
|
organization_permissions: false,
|
|
|
|
})
|
2025-03-12 02:16:28 +08:00
|
|
|
}
|