From c4908b7765ccff00556f60649e8a655472d60468 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 4 Jun 2026 02:34:01 +0200 Subject: [PATCH] feat: API endpoints for any user's following/followers --- crates/presentation/src/handlers/api.rs | 44 +++++++++++++++++++++++++ crates/presentation/src/routes.rs | 8 +++++ 2 files changed, 52 insertions(+) diff --git a/crates/presentation/src/handlers/api.rs b/crates/presentation/src/handlers/api.rs index ed467fc..84d2ef0 100644 --- a/crates/presentation/src/handlers/api.rs +++ b/crates/presentation/src/handlers/api.rs @@ -770,6 +770,50 @@ pub async fn get_followers( } } +#[cfg(feature = "federation")] +pub async fn get_user_following( + State(state): State, + _user: AuthenticatedUser, + Path(user_id): Path, +) -> impl IntoResponse { + match state.ap_service.get_following(user_id).await { + Ok(actors) => Json(ActorListResponse { + actors: actors + .into_iter() + .map(|a| RemoteActorDto { + handle: a.handle, + display_name: a.display_name, + url: a.url, + }) + .collect(), + }) + .into_response(), + Err(e) => ap_err(e).into_response(), + } +} + +#[cfg(feature = "federation")] +pub async fn get_user_followers( + State(state): State, + _user: AuthenticatedUser, + Path(user_id): Path, +) -> impl IntoResponse { + match state.ap_service.get_accepted_followers(user_id).await { + Ok(actors) => Json(ActorListResponse { + actors: actors + .into_iter() + .map(|a| RemoteActorDto { + handle: a.handle, + display_name: a.display_name, + url: a.url, + }) + .collect(), + }) + .into_response(), + Err(e) => ap_err(e).into_response(), + } +} + #[cfg(feature = "federation")] #[utoipa::path( post, path = "/api/v1/social/follow", diff --git a/crates/presentation/src/routes.rs b/crates/presentation/src/routes.rs index 6693f3e..11e8218 100644 --- a/crates/presentation/src/routes.rs +++ b/crates/presentation/src/routes.rs @@ -322,6 +322,14 @@ fn api_routes(rate_limit: u64) -> Router { ) .route("/users", routing::get(handlers::api::list_users)) .route("/users/{id}", routing::get(handlers::api::get_user_profile)) + .route( + "/users/{id}/following", + routing::get(handlers::api::get_user_following), + ) + .route( + "/users/{id}/followers", + routing::get(handlers::api::get_user_followers), + ) .route( "/import/sessions", routing::post(handlers::import::api_post_session),