this repo has no description
1use crate::state::AppState; 2use axum::{ 3 Json, 4 extract::{Query, State}, 5 http::StatusCode, 6 response::{IntoResponse, Response}, 7}; 8use serde::Deserialize; 9use serde_json::json; 10#[derive(Deserialize)] 11pub struct DescribeRepoInput { 12 pub repo: String, 13} 14pub async fn describe_repo( 15 State(state): State<AppState>, 16 Query(input): Query<DescribeRepoInput>, 17) -> Response { 18 let user_row = if input.repo.starts_with("did:") { 19 sqlx::query!("SELECT id, handle, did FROM users WHERE did = $1", input.repo) 20 .fetch_optional(&state.db) 21 .await 22 .map(|opt| opt.map(|r| (r.id, r.handle, r.did))) 23 } else { 24 sqlx::query!("SELECT id, handle, did FROM users WHERE handle = $1", input.repo) 25 .fetch_optional(&state.db) 26 .await 27 .map(|opt| opt.map(|r| (r.id, r.handle, r.did))) 28 }; 29 let (user_id, handle, did) = match user_row { 30 Ok(Some((id, handle, did))) => (id, handle, did), 31 _ => { 32 return ( 33 StatusCode::NOT_FOUND, 34 Json(json!({"error": "NotFound", "message": "Repo not found"})), 35 ) 36 .into_response(); 37 } 38 }; 39 let collections_query = 40 sqlx::query!("SELECT DISTINCT collection FROM records WHERE repo_id = $1", user_id) 41 .fetch_all(&state.db) 42 .await; 43 let collections: Vec<String> = match collections_query { 44 Ok(rows) => rows.iter().map(|r| r.collection.clone()).collect(), 45 Err(_) => Vec::new(), 46 }; 47 let did_doc = json!({ 48 "id": did, 49 "alsoKnownAs": [format!("at://{}", handle)] 50 }); 51 Json(json!({ 52 "handle": handle, 53 "did": did, 54 "didDoc": did_doc, 55 "collections": collections, 56 "handleIsCorrect": true 57 })) 58 .into_response() 59}