2020-05-16 14:04:08 +00:00
|
|
|
use crate::websocket::WebsocketInfo;
|
|
|
|
use diesel::{
|
|
|
|
r2d2::{ConnectionManager, Pool},
|
|
|
|
PgConnection,
|
2020-02-03 03:51:54 +00:00
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
use failure::Error;
|
2019-05-05 05:20:38 +00:00
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
pub mod comment;
|
2019-05-05 05:20:38 +00:00
|
|
|
pub mod community;
|
|
|
|
pub mod post;
|
|
|
|
pub mod site;
|
2019-09-07 15:35:05 +00:00
|
|
|
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> {
|
2019-09-07 15:35:05 +00:00
|
|
|
data: T,
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
|
2020-04-24 14:04:36 +00:00
|
|
|
impl<Data> Oper<Data> {
|
|
|
|
pub fn new(data: Data) -> Oper<Data> {
|
2020-01-16 14:39:08 +00:00
|
|
|
Oper { data }
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 03:59:07 +00:00
|
|
|
pub trait Perform {
|
2020-04-21 20:40:03 +00:00
|
|
|
type Response: serde::ser::Serialize + Send;
|
2020-04-20 03:59:07 +00:00
|
|
|
|
2020-04-19 22:08:25 +00:00
|
|
|
fn perform(
|
|
|
|
&self,
|
|
|
|
pool: Pool<ConnectionManager<PgConnection>>,
|
|
|
|
websocket_info: Option<WebsocketInfo>,
|
2020-04-20 03:59:07 +00:00
|
|
|
) -> Result<Self::Response, Error>;
|
2019-05-05 05:20:38 +00:00
|
|
|
}
|