]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Iframely and pictshare backend mostly done.
[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, naive_from_unix, naive_now, remove_slurs,
22   slur_check, slurs_vec_to_str,
23 };
24 use diesel::PgConnection;
25 use failure::Error;
26 use serde::{Deserialize, Serialize};
27
28 pub mod comment;
29 pub mod community;
30 pub mod post;
31 pub mod site;
32 pub mod user;
33
34 #[derive(Fail, Debug)]
35 #[fail(display = "{{\"error\":\"{}\"}}", message)]
36 pub struct APIError {
37   pub message: String,
38 }
39
40 impl APIError {
41   pub fn err(msg: &str) -> Self {
42     APIError {
43       message: msg.to_string(),
44     }
45   }
46 }
47
48 pub struct Oper<T> {
49   data: T,
50 }
51
52 impl<T> Oper<T> {
53   pub fn new(data: T) -> Oper<T> {
54     Oper { data }
55   }
56 }
57
58 pub trait Perform<T> {
59   fn perform(&self, conn: &PgConnection) -> Result<T, Error>
60   where
61     T: Sized;
62 }