buster/api/libs/handlers/src/collections/get_collection_handler.rs

32 lines
987 B
Rust
Raw Normal View History

2025-03-18 22:14:29 +08:00
use anyhow::{anyhow, Result};
use database::{collections::fetch_collection, enums::AssetPermissionRole};
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,
})
}