]> Untitled Git - lemmy.git/blob - server/src/api/mod.rs
Rework imports
[lemmy.git] / server / src / api / mod.rs
1 use crate::websocket::WebsocketInfo;
2 use diesel::{
3   r2d2::{ConnectionManager, Pool},
4   PgConnection,
5 };
6 use failure::Error;
7
8 pub mod comment;
9 pub mod community;
10 pub mod post;
11 pub mod site;
12 pub mod user;
13
14 #[derive(Fail, Debug)]
15 #[fail(display = "{{\"error\":\"{}\"}}", message)]
16 pub struct APIError {
17   pub message: String,
18 }
19
20 impl APIError {
21   pub fn err(msg: &str) -> Self {
22     APIError {
23       message: msg.to_string(),
24     }
25   }
26 }
27
28 pub struct Oper<T> {
29   data: T,
30 }
31
32 impl<Data> Oper<Data> {
33   pub fn new(data: Data) -> Oper<Data> {
34     Oper { data }
35   }
36 }
37
38 pub trait Perform {
39   type Response: serde::ser::Serialize + Send;
40
41   fn perform(
42     &self,
43     pool: Pool<ConnectionManager<PgConnection>>,
44     websocket_info: Option<WebsocketInfo>,
45   ) -> Result<Self::Response, Error>;
46 }