use axum::{Json, extract::Path}; use serde_json::{json, Value}; use crate::{atproto::{did_resolver::{fetch_did_doc, identifier_to_did}, fetch_blob_count::fetch_blob_count, pds_resolver::extract_pds}, errors::api_error::ApiError}; #[utoipa::path( get, path = "/user/{identifier}/data/blob-count", tag = "user", params( ("identifier" = String, Path, description = "Handle or DID") ), responses( ( status = 200, description = "Blob Count", body = serde_json::Value, example = json!({ "blobCount": 61 }) ), ( 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_blob_count_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 blob_count = fetch_blob_count(pds.clone(), did.clone()).await?; Ok(Json(json!({ "blobCount": blob_count, }))) }