use crate::api::comment::*; use crate::api::community::*; use crate::api::post::*; use crate::api::site::*; use crate::api::user::*; use crate::api::{Oper, Perform}; use actix_web::{web, HttpResponse}; use diesel::r2d2::{ConnectionManager, Pool}; use diesel::PgConnection; use failure::Error; use serde::Serialize; type DbParam = web::Data>>; #[rustfmt::skip] pub fn config(cfg: &mut web::ServiceConfig) { cfg .route("/api/v1/login", web::post().to(route::)) .route("/api/v1/register", web::post().to(route::)) .route("/api/v1/create_community", web::post().to(route::)) .route("/api/v1/create_post", web::post().to(route::)) .route("/api/v1/list_communities", web::get().to(route::)) .route("/api/v1/list_categories", web::get().to(route::)) .route("/api/v1/get_post", web::get().to(route::)) .route("/api/v1/get_community", web::get().to(route::)) .route("/api/v1/create_communent", web::post().to(route::)) .route("/api/v1/edit_comment", web::post().to(route::)) .route("/api/v1/save_comment", web::post().to(route::)) .route("/api/v1/create_comment_like", web::post().to(route::)) .route("/api/v1/get_posts", web::get().to(route::)) .route("/api/v1/create_post_like", web::post().to(route::)) .route("/api/v1/edit_post", web::post().to(route::)) .route("/api/v1/save_post", web::post().to(route::)) .route("/api/v1/edit_community", web::post().to(route::)) .route("/api/v1/follow_community", web::post().to(route::)) .route("/api/v1/get_followed_communities", web::get().to(route::)) .route("/api/v1/get_user_details", web::get().to(route::)) .route("/api/v1/get_replies", web::get().to(route::)) .route("/api/v1/get_user_mentions", web::get().to(route::)) .route("/api/v1/edit_user_mention", web::post().to(route::)) .route("/api/v1/get_modlog", web::get().to(route::)) .route("/api/v1/ban_from_community", web::post().to(route::)) .route("/api/v1/add_mod_to_community", web::post().to(route::)) .route("/api/v1/create_site", web::post().to(route::)) .route("/api/v1/edit_site", web::post().to(route::)) .route("/api/v1/get_site", web::get().to(route::)) .route("/api/v1/add_admin", web::post().to(route::)) .route("/api/v1/ban_user", web::post().to(route::)) .route("/api/v1/search", web::post().to(route::)) .route("/api/v1/mark_all_as_read", web::post().to(route::)) .route("/api/v1/save_user_settings", web::post().to(route::)) .route("/api/v1/transfer_community", web::post().to(route::)) .route("/api/v1/transfer_site", web::post().to(route::)) .route("/api/v1/delete_account", web::post().to(route::)) .route("/api/v1/password_reset", web::post().to(route::)) .route("/api/v1/password_change", web::post().to(route::)); } fn perform(data: Request, db: DbParam) -> Result where Response: Serialize, Oper: Perform, { let conn = match db.get() { Ok(c) => c, Err(e) => return Err(format_err!("{}", e)), }; let oper: Oper = Oper::new(data); let response = oper.perform(&conn); Ok(HttpResponse::Ok().json(response?)) } async fn route(data: web::Query, db: DbParam) -> Result where Data: Serialize, Response: Serialize, Oper: Perform, { perform::(data.0, db) }