learn and share notes on atproto (wip) 馃
malfestio.stormlightlabs.org/
readability
solid
axum
atproto
srs
1use crate::middleware::auth::UserContext;
2use crate::state::SharedState;
3use axum::{
4 Json,
5 extract::{Extension, Path, State},
6 http::StatusCode,
7 response::IntoResponse,
8};
9use serde_json::json;
10
11/// GET /api/export/:collection
12/// Export data for the authenticated user
13pub async fn export_collection(
14 State(state): State<SharedState>, Extension(user): Extension<UserContext>, Path(collection): Path<String>,
15) -> impl IntoResponse {
16 match collection.as_str() {
17 "decks" => match state.deck_repo.get_decks_by_user(&user.did).await {
18 Ok(decks) => Json(json!(decks)).into_response(),
19 Err(e) => {
20 tracing::error!("Failed to export decks: {:?}", e);
21 (
22 StatusCode::INTERNAL_SERVER_ERROR,
23 Json(json!({"error": "Failed to export decks"})),
24 )
25 .into_response()
26 }
27 },
28 "notes" => match state.note_repo.get_notes_by_user(&user.did).await {
29 Ok(notes) => Json(json!(notes)).into_response(),
30 Err(e) => {
31 tracing::error!("Failed to export notes: {:?}", e);
32 (
33 StatusCode::INTERNAL_SERVER_ERROR,
34 Json(json!({"error": "Failed to export notes"})),
35 )
36 .into_response()
37 }
38 },
39 _ => (StatusCode::BAD_REQUEST, Json(json!({"error": "Invalid collection"}))).into_response(),
40 }
41}