use axum::{Json, extract::Path}; use serde_json::{json, Value}; use crate::{atproto::{did_resolver::{fetch_did_doc, identifier_to_did}, fetch_collections::fetch_collections, parse_collections::parse_collections, pds_resolver::extract_pds}, errors::api_error::ApiError}; #[utoipa::path( get, path = "/user/{identifier}/data/collections", tag = "user", params( ("identifier" = String, Path, description = "Handle or DID") ), responses( ( status = 200, description = "Organized list of the users collections", body = serde_json::Value, example = json!({ "collectionsCount": "31", "collections": { "bsky.app": [ "app.bsky.feed.post", "app.bsky.graph.follow" ], "standard.site": [ "site.standard.document", "site.standard.publication" ] } }) ), ( status = 400, description = "Invalid handle or DID", body = serde_json::Value, example = json!({"error": "invalid handle or DID"}) ), ( status = 404, description = "No handle or PDS found for the DID", body = serde_json::Value, example = json!({"error": "No handles found associated with DID"}) ), ( status = 500, description = "Internal error: conversion, Redis, or unknown failure", body = serde_json::Value, example = json!({"error": "An unknown error occurred"}) ), ( status = 502, description = "Upstream resolution failed", body = serde_json::Value, example = json!({"error": "could not resolve identity"}) ) ) )] pub async fn fetch_collection_data(Path(identifier): Path) -> Result, ApiError> { let did = identifier_to_did(identifier.clone()).await?; let doc = fetch_did_doc(did.clone()).await?; let pds = extract_pds(doc.clone()).await?; let collections = fetch_collections(pds, did).await?; let parsed = parse_collections(collections.clone()); Ok(Json(json!({ "collectionCount": &collections.len(), "collections": parsed }))) }