1 use crate::api::community::ListCommunities;
2 use crate::api::Perform;
3 use crate::api::{Oper, UserOperation};
5 use crate::settings::Settings;
6 use actix_web::web::Query;
7 use actix_web::{web, HttpResponse};
8 use diesel::r2d2::{ConnectionManager, Pool};
9 use diesel::PgConnection;
11 pub fn config(cfg: &mut web::ServiceConfig) {
12 if Settings::get().federation_enabled {
13 println!("federation enabled, host is {}", Settings::get().hostname);
16 "/federation/c/{community_name}",
17 web::get().to(apub::community::get_apub_community),
20 "/federation/c/{community_name}/followers",
21 web::get().to(apub::community::get_apub_community_followers),
24 "/federation/u/{user_name}",
25 web::get().to(apub::user::get_apub_user),
27 // TODO: this is a very quick and dirty implementation for http api calls
29 "/api/v1/communities/list",
31 |query: Query<ListCommunities>, db: web::Data<Pool<ConnectionManager<PgConnection>>>| {
32 let res = Oper::new(UserOperation::ListCommunities, query.into_inner())
33 .perform(&db.get().unwrap())
36 .content_type("application/json")
37 .body(serde_json::to_string(&res).unwrap())