]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Adding websocket notification system.
[lemmy.git] / server / src / api / mod.rs
1 use crate::db::category::*;
2 use crate::db::comment::*;
3 use crate::db::comment_view::*;
4 use crate::db::community::*;
5 use crate::db::community_view::*;
6 use crate::db::moderator::*;
7 use crate::db::moderator_views::*;
8 use crate::db::password_reset_request::*;
9 use crate::db::post::*;
10 use crate::db::post_view::*;
11 use crate::db::private_message::*;
12 use crate::db::private_message_view::*;
13 use crate::db::site::*;
14 use crate::db::site_view::*;
15 use crate::db::user::*;
16 use crate::db::user_mention::*;
17 use crate::db::user_mention_view::*;
18 use crate::db::user_view::*;
19 use crate::db::*;
20 use crate::{
21   extract_usernames, fetch_iframely_and_pictshare_data, generate_random_string, naive_from_unix,
22   naive_now, remove_slurs, send_email, slur_check, slurs_vec_to_str,
23 };
24
25 use crate::rate_limit::RateLimitInfo;
26 use crate::settings::Settings;
27 use crate::websocket::UserOperation;
28 use crate::websocket::{
29   server::{
30     JoinCommunityRoom, JoinPostRoom, JoinUserRoom, SendAllMessage, SendComment,
31     SendCommunityRoomMessage, SendPost, SendUserRoomMessage,
32   },
33   WebsocketInfo,
34 };
35 use diesel::r2d2::{ConnectionManager, Pool};
36 use diesel::PgConnection;
37 use failure::Error;
38 use log::{error, info};
39 use serde::{Deserialize, Serialize};
40 use std::str::FromStr;
41
42 pub mod comment;
43 pub mod community;
44 pub mod post;
45 pub mod site;
46 pub mod user;
47
48 #[derive(Fail, Debug)]
49 #[fail(display = "{{\"error\":\"{}\"}}", message)]
50 pub struct APIError {
51   pub message: String,
52 }
53
54 impl APIError {
55   pub fn err(msg: &str) -> Self {
56     APIError {
57       message: msg.to_string(),
58     }
59   }
60 }
61
62 pub struct Oper<T> {
63   data: T,
64 }
65
66 impl<T> Oper<T> {
67   pub fn new(data: T) -> Oper<T> {
68     Oper { data }
69   }
70 }
71
72 pub trait Perform<T> {
73   fn perform(
74     &self,
75     pool: Pool<ConnectionManager<PgConnection>>,
76     websocket_info: Option<WebsocketInfo>,
77     rate_limit_info: Option<RateLimitInfo>,
78   ) -> Result<T, Error>
79   where
80     T: Sized;
81 }