lemmy/server/src/api/mod.rs

80 lines
1.8 KiB
Rust
Raw Normal View History

use crate::db::category::*;
2019-06-03 17:47:12 +00:00
use crate::db::comment::*;
use crate::db::comment_view::*;
use crate::db::community::*;
2019-06-03 17:47:12 +00:00
use crate::db::community_view::*;
use crate::db::moderator::*;
use crate::db::moderator_views::*;
2019-11-02 06:43:21 +00:00
use crate::db::password_reset_request::*;
use crate::db::post::*;
use crate::db::post_view::*;
use crate::db::private_message::*;
use crate::db::private_message_view::*;
use crate::db::site::*;
use crate::db::site_view::*;
use crate::db::user::*;
use crate::db::user_mention::*;
use crate::db::user_mention_view::*;
use crate::db::user_view::*;
use crate::db::*;
use crate::{
extract_usernames, fetch_iframely_and_pictshare_data, generate_random_string, naive_from_unix,
naive_now, remove_slurs, send_email, slur_check, slurs_vec_to_str,
};
use crate::settings::Settings;
use crate::websocket::UserOperation;
use crate::websocket::{
server::{
JoinCommunityRoom, JoinPostRoom, JoinUserRoom, SendAllMessage, SendComment,
SendCommunityRoomMessage, SendPost, SendUserRoomMessage,
},
WebsocketInfo,
};
use diesel::r2d2::{ConnectionManager, Pool};
use diesel::PgConnection;
use failure::Error;
use log::{error, info};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
2019-05-05 05:20:38 +00:00
pub mod comment;
2019-05-05 05:20:38 +00:00
pub mod community;
pub mod post;
pub mod site;
pub mod user;
2019-05-05 05:20:38 +00:00
#[derive(Fail, Debug)]
2020-01-16 14:39:08 +00:00
#[fail(display = "{{\"error\":\"{}\"}}", message)]
2019-05-05 05:20:38 +00:00
pub struct APIError {
2019-05-05 16:20:30 +00:00
pub message: String,
2019-05-05 05:20:38 +00:00
}
impl APIError {
2020-01-16 14:39:08 +00:00
pub fn err(msg: &str) -> Self {
2019-05-05 05:20:38 +00:00
APIError {
message: msg.to_string(),
}
}
}
pub struct Oper<T> {
data: T,
2019-05-05 05:20:38 +00:00
}
impl<T> Oper<T> {
2020-01-16 14:39:08 +00:00
pub fn new(data: T) -> Oper<T> {
Oper { data }
2019-05-05 05:20:38 +00:00
}
}
pub trait Perform {
type Response: serde::ser::Serialize;
fn perform(
&self,
pool: Pool<ConnectionManager<PgConnection>>,
websocket_info: Option<WebsocketInfo>,
) -> Result<Self::Response, Error>;
2019-05-05 05:20:38 +00:00
}